[CMake] Linking to .a files under AIX

jens persson jens at persson.cx
Tue Dec 15 06:49:33 EST 2009


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


More information about the CMake mailing list