Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

Linking an external library when building COSP (libcosp.a)

jshaw35

Jonah Shaw
New Member
Hi all,

I would like to link external libraries when building the libcosp.a library. Specifically, I have built a separate external library that I call functions/routines from in the COSP code. In the COSP offline driver, I link this library when creating the executable for the offline driver. In CESM, however, I would like to link the separate library to the COSP library (libcosp.a) rather than an executable. There are variable naming conflicts between the Makefile for the external library and the rest of CESM at the "cesm.exe" level that have stopped me from linking when the final executable is built. It also makes more sense to link the external libraries directly to the COSP library.

So my question is, how can I link in the external libraries when building the libcosp.a library?

When linking the external libraries to an executable (e.g. the COSP offline driver), I link RTTOV by modifying the flags that are used when the executable is built. For example, when building the COSP offline driver, I append to the LDFLAGS variable. This variable (LDFLAGS) is then used when the driver executable is built at the end. Code for reference below.

# Append to the LDFLAGS variable if linking the external library (RTTOV)
ifdef RTTOV
LDFLAGS += $(LIBS) $(LLIBS) $(LDFLAGS_NETCDF) $(LDFLAGS_HDF5) $(LDFLAGS_ARCH) $(LDFLAGS_LAPACK)
endif


# Then LDFLAGS is used when the COSP offline driver is built.
%: %.o
$(F90) $(F90FLAGS) -o $@ $^ $(LDFLAGS)

Can I add flags to the rule used to build the libcosp.a library (below) that will link in the RTTOV libraries and their dependencies in a similar way? The Makefile language for building a library is different from building an executable, but I am hoping I just need the appropriate syntax. i.e. Something analogous to the LDFLAGS variable described above.

Rule used to build the libcosp.a library:
$(LIBRARY): $(COSP_OBJS)
ar -rvs $(LIBRARY) $(COSP_OBJS)

Thank you!
Jonah
 
Top