[CMake] linking with a .a file

Pierre Chifflier chifflier at cpe.fr
Fri Sep 29 10:45:55 EDT 2006


Hi,

I am currently trying to convert my project (wzdftpd) to cmake. The last
remaining problem is the following:

[short version]

I have a module which must either modify LDFLAGS, or link with an
archive file (DynaLoader.a). I tried to add this file in the
ADD_LIBRARY(...) target, in the LINK_FLAG property and in
TARGET_LINK_LIBRARIES without success.

If I use
  TARGET_LINK_LIBRARIES (wzd_perl DynaLoader.a)
Then cmake will convert it to:
  -lDynaLoader
which is wrong.

Is there a proper way to include a .a file after object files in the
compilation ?

Build platform: Debian unstable (linux), cmake 2.4.3, gcc 4.1


[long]

The server tries to load a module (shared library) which contains a
perl interpreter. With cmake this fails:
dlerror: libwzd_perl.so: undefined symbol: boot_DynaLoader

This symbol is contained in an archive file (DynaLoader.a), which must
be (statically) linked to the target (libwzd_perl.so). Using autoconf,
my makefile contains something like:
LDFLAGS += `perl -MExtUtils::Embed -e ldopts`

This command expands to:
-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

Since there seems to be no way to change LDFLAGS with cmake, I try to
add the .a file in object files.

If I add DynaLoader.a in the LINK_FLAGS property of the target, it
does not work.
The generate build line is:
/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
-lwzd_core -lperl -lpthread -lssl
-Wl,-rpath,/home/pollux/WORK/PROGS/wzd/WZDFTPD/wzdftpd-cmake/build/libwzd-core

However:
$ nm build/modules/perl/libwzd_perl.so|grep Dyna
         U boot_DynaLoader

Using the same compilation command, except the position of DynaLoader.a _after_ the .o files works fine:
$ nm build/modules/perl/libwzd_perl.so|grep Dyna
000099b0 T boot_DynaLoader

So the order is wrong, .a file must be added _after_ .o files.


Thanks for help,
Pierre


More information about the CMake mailing list