[CMake] CMake being too clever with library names

Rodolfo Lima rodolfo at rodsoft.org
Sat Dec 29 21:26:08 EST 2007


Hi people.
Sometimes I feel that CMake tries to be smarter then me when dealing
with library names. For instance, suppose the following setup:

* project
	CMakeLists.txt
	test.cpp
	video.a

CMakeLists.txt:
add_executable(test test.cpp)
target_link_libraries(test ${CMAKE_SOURCE_DIR}/video.a)

test.cpp:
int main(){}

Notice that I'm specifying the library I want to link to with its
complete path. When I run make, g++ outputs an error:

/usr/lib/gcc/i686-pc-linux-gnu/4.2.2/../../../../i686-pc-linux-gnu/bin/ld:
cannot find -lvideo
collect2: ld returned 1 exit status

The command line of the linker is:
/usr/bin/c++     -fPIC "CMakeFiles/test.dir/test.cpp.o"  -o test
-rdynamic -L/home/rodolfo/src/tst -Wl,-Bstatic -lvideo -Wl,-Bdynamic
-Wl,-rpath,/home/rodolfo/src/tst

First problem: why all the fuss with -rpath, etc, if I'm linking
statically? Why -rdynamic ?
Second: if I'm specifying the complete path of video.a library, why does
it try to link it with -l and set the library path with -L? I know the
library name is non standard (in linux), but this is a simplified case
of a problem I'm having, and the static library should be simply put on
the command line, nothing more than that.

The problem I'm having is when compiling on windows using mingw-g++.
Some external libraries are ".lib", others are ".a". Since cmake's
default is ".lib" on windows, I use target_link_libraries to the
libraries with extension ".a" specifying their complete paths, but as
the simple case above shows, this fails.

Regards,
rod



More information about the CMake mailing list