[cgma-dev] Linking to iGeom

Steve Jackson sjackson at cae.wisc.edu
Tue Jan 12 13:59:57 CST 2010


I am trying to learn the most correct and robust way to specify linker flags in makefiles when building programs against CGM's iGeom interface.

A CGM installation comes with a makefile include, iGeom-Defs.inc.  This file exports the make variables IGEOM_LDFLAGS and IGEOM_LTFLAGS.  IGEOM_LTFLAGS is a collection of one or more -R{directory} flags, indicating rpaths to external library dependencies (usually the ACIS libraries).  I want to find the best way to use the IGEOM_LTFLAGS variable in my own makefiles.

In a standard GNU/Linux/gcc setup, -R is a linker option, not a compiler option.  Some version of gcc recognize -R as a linker option and will pass it through on a linking step, but other versions will not.  (I'm using gcc 4.3.2, and on my system, gcc -R causes an error.)  So `gcc $(IGEOM_LTFLAGS)` is not a good choice.

The more robust way to pass options through gcc to the linker is to use the prefix argument '-Wl,{args}'.  Using this method, `gcc -Wl,($IGEOM_LTFLAGS)` works if IGEOM_LTFLAGS specifies only one -R path.  But in some cases (such as a cubit-based installation), IGEOM_LTFLAGS has multiple -R paths, separated by spaces.  So `gcc -Wl,$(IGEOM_LTFLAGS)` is also not a good choice.

Here is a third option, which changes the IGEOM_LTFLAGS from a linker-compatible list of arguments to a gcc-compatible list of arguments:

comma:= ,
empty:=
space:= $(empty) $(empty)
FIXED_LTFLAGS = $(subst $(space), $(comma),$(strip $(IGEOM_LTFLAGS)))

The above snippet converts spaces to commas, changing "-R/path/the/first -R/path/the/second" to "-R/path/the/first,-R/path/the/second".  This new format is compatible with gcc's -Wl syntax.  So, in a makefile with the above commands, `gcc -Wl,$(FIXED_LTFLAGS)` works.  

But this last option seems convoluted.  Am I missing something easier?
~S


More information about the cgma-dev mailing list