[CMake] linking with a .a file

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sat Sep 30 16:37:04 EDT 2006


On 2006-09-30 20:40+0200 Pierre Chifflier wrote:

> On Sat, Sep 30, 2006 at 11:13:57AM -0700, Alan W. Irwin wrote:

>> Actually -l (when combined with -L) is a standard way to specify libraries
>> (whether they are static or shared) to the linker.  To make sure cmake
>> generates the appropriate combination of -L and -l options, just specify the
>> full path to DynaLoader.a, i.e.,
>> /usr/lib/perl/5.8/auto/DynaLoader/DynaLoader.a.
>>
>
> If I add this path to TARGET_LINK_LIBRARIES, cmake generates -l/-L
> options, but that does not work:
>
> /usr/bin/gcc  -fPIC   -O3 -DNDEBUG -Wl,-E  -L/usr/local/lib
> /usr/lib/perl/5.8/auto/DynaLoader/DynaLoader.a
> -L/usr/lib/perl/5.8/CORE -lperl -ldl -lm -lpthread -lc -lcrypt -shared
> -Wl,-soname,libwzd_perl.so -o libwzd_perl.so
> "CMakeFiles/wzd_perl.dir/libwzd_perl.o"
> -L/home/pollux/WORK/PROGS/wzd/WZDFTPD/wzdftpd-cmake/build/libwzd-core
> -L/usr/lib/perl/5.8/auto/DynaLoader -lwzd_core -lDynaLoader -lperl
> ^^^^                                             ^^^
>
> -lpthread -lssl
> -Wl,-rpath,/home/pollux/WORK/PROGS/wzd/WZDFTPD/wzdftpd-cmake/build/libwzd-core:/usr/lib/perl/5.8/auto/DynaLoader
> /usr/bin/ld: cannot find -lDynaLoader
> collect2: ld returned 1 exit status
>

Sorry, I missed the fact that DynaLoader.a had a non-standard name without
the lib prefix.  In this case the -L/-l combination of options will not work.

My next suggestion would have been to use SET_TARGET_PROPERTIES with
LINK_FLAGS, but you have already tried that, and from your result above it
obviously puts /usr/lib/perl/5.8/auto/DynaLoader/DynaLoader.a above in the
place where you have linking flags (as might be expected) rather than where
libraries should be specified.

So perhaps it is time for a feature request to cmake to add support to
TARGET_LINK_LIBRARIES for the case of libraries that are named without the
"lib" prefix.

At this point, I think you are pretty close to being stuck.  However, there
is one last thing you might want to try.

Make a custom target that uses

COMMAND ${CMAKE_COMMAND} -E create_symlink
/usr/lib/perl/5.8/auto/DynaLoader/DynaLoader.a
libDynaLoader.a

to create a "lib" symlink version of the library that you can refer to in
TARGET_LINK_LIBRARIES.

I am pretty sure this will work (especially if you pay attention to target
dependencies), but I haven't tried it myself.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list