Linking to .a files under AIX

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Linking to .a files under AIX

jens persson
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
<[hidden email]>
Mäster Olofsväg 24
S-224 66 LUND;SWEDEN
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Linking to .a files under AIX

jens persson
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 <[hidden email]>:

> 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
> <[hidden email]>
> Mäster Olofsväg 24
> S-224 66 LUND;SWEDEN
>



--
jens persson
<[hidden email]>
Mäster Olofsväg 24
S-224 66 LUND;SWEDEN
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake