[CMake] Strange problem creating and linking against a static lib

Joachim Ziegler ziegler at mpi-sb.mpg.de
Wed Jan 7 04:33:34 EST 2009


Since I did not get any response, I'll try to shorten the problem
description: I try to build a static convenience lib holding all my
.o-files and then to link statically against it and all other libs.

In my CMakeLists.txt, I have

SET(CMAKE_EXE_LINKER_FLAGS -static)
ADD_LIBRARY(baselib STATIC ${BASEFILES})
ADD_EXECUTABLE(startCompletionServer StartCompletionServer.cpp)
TARGET_LINK_LIBRARIES(startCompletionServer baselib pthread z)

The executable that is created is somehow broken:

$ ./startCompletionServer
-bash: ./startCompletionServer: No such file or directory

although it is obviously there:

$ ll ./startCompletionServer
-rwxr-xr-x 1 ziegler Mehlhorn 2896216 Jan  7 10:26 ./startCompletionServer

I suppose the problem is in the link line, which says:

/usr/bin/X11/c++      -fPIC -static
"CMakeFiles/startCompletionServer.dir/StartCompletionServer.o"   -o
startCompletionServer -rdynamic -L/KM/home-0/ziegler/tmp/build
-Wl,-Bstatic -lbaselib -Wl,-Bdynamic -lpthread -lz
-Wl,-rpath,/KM/home-0/ziegler/tmp/build


Why is there a "-Wl,-Bdynamic -lpthread -lz" in it? Shouldn't the

SET(CMAKE_EXE_LINKER_FLAGS -static)

specify static linkage against all libs?

Any hints highly appreciated,
Joachim






More information about the CMake mailing list