[CMake] Linking to .a files under AIX

jens persson jens at persson.cx
Tue Dec 15 09:30:08 EST 2009


Hello again!

I found my error and have fixed it, documenting it here to aid the
next person encountering it.

I need to override the linker flags to remove the -bexpall flag and
doing so I had accidentaly removed the -bnoipath option to so changing
the lines:

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-brtl")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,-brtl")

to

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-brtl,-bnoipath")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,-brtl,-bnoipath")

solved the problem.

Mea culpa

/jp

2009/12/15 jens persson <jens at persson.cx>:
> Hello
>
> I have a problem with linking to dynamic libraries on AIX:
>
> A target (target_a) needs to link to a external dynamic library
> (xerces) that I use find_library() to find. Something along these
> lines:
>
> find_library(XERCES
>  NAMES libxerces-c2_7_0.a
>  PATHS ${LIB_PATH}
> )
> add_executable(target_a
>  foo.c
> )
> target_link_libraries(target_a
>        library_b
>        ${XERCES}
> )
> set_target_properties(target_a PROPERTIES
>    RUNTIME_OUTPUT_DIRECTORY "../../bin/"
> )
>
> (It is library_b that is the real user of xerces) The problem is that
> when linking target_a the path to xerces is given in relation to the
> buildspace (i.e ../../../external_libs/xexes/libxerces-c2_7_0.a )
> which becomes embeded into the binary (visable when using dump) and
> when the binary is moved to the target directory the relative path is
> no longer valid :-( ).
>
> I think that some of the problem is related to that .a files can be
> both static and dynamic on AIX and when cmake compliles the command
> line for cc it thinks that it is a static lib but cc/ld concludes that
> it is a dynamic library and makes its magic to embed the path.
>
> I have tried various ways to resolve the problem:
> * I create an imported target for xerces the I linked to.
> * I have made tried to link library_b to xerces (both using ${XERCES}
> and using the imported target)
> * Giving extra linkflags -L and -l when building the target
>
> the last one works, but it feels like a hack.
>
> I'm hoping someone have found a solution to the problems that don't
> involves setting linkflags on all our targets and are willing to share
> it :-)
>
> thanks in advance
> /jp
> --
> jens persson
> <jens at persson.cx>
> Mäster Olofsväg 24
> S-224 66 LUND;SWEDEN
>



-- 
jens persson
<jens at persson.cx>
Mäster Olofsväg 24
S-224 66 LUND;SWEDEN


More information about the CMake mailing list