[cgma-dev] Linking to iGeom
Jason Kraftcheck
kraftche at cae.wisc.edu
Tue Jan 12 14:14:11 CST 2010
Steve Jackson wrote:
> 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.
>
The 'LT' in LTFLAGS refers to GNU libtool. That is the only way that such
flags can be used portably, as not all compilers/linkers support them and
there doesn't seem to be a consensus on the flag used.
> 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.
>
Things are a lot more complicated if you consider compilers other than just gcc.
> 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.
>
The following is probably a lot more portable:
FIXED_FLAGS = $(IGEOM_LTFLAGS:%=-Wl,%)
This will result a different but equivalent value for FIXED_FLAGS.
Something like:
-Wl,-R/path/the/first -Wl,-R/path/the/second ...
> But this last option seems convoluted. Am I missing something easier? ~S
iGeom-Defs.inc does not provide compiler flags for this because a) there is
no portable way of specifying this and b) the method that libtool detects
(and what it does if no method is available) is difficult to extract during
the configuration process. The preferred methods for addressing this issue
are to either a) use libtool or b) set the environmental variable
LD_LIBRARY_PATH to the list of directories where ACIS and other shared
libraries that CGM requires can be found.
- jason
More information about the cgma-dev
mailing list