[CMake] fun with Boost - swap absolute library path for -L and -l?

Adam J Richardson fatman at crackmonkey.us
Mon Nov 1 12:37:40 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,

I'm having some fun making link errors with the help of Boost on Win32.

With a main.cc of:

"
#include "boost/thread.hpp"

int main(int, char **) {
   boost::thread t;
   return 0;
}
"

and a CMakeLists.txt of:

"
cmake_minimum_required(VERSION "2.8")
project("orrible")
add_executable(orrible orrible/main.cc)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0")
find_package(Boost 1.38 REQUIRED COMPONENTS thread)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(orrible ${Boost_LIBRARIES})
"

I can produce the error:

"
CMakeFiles/orrible.dir/orrible/main.cc.obj:main.cc:(.text+0x17): undefined refer
ence to `_imp___ZN5boost6threadC1Ev'
CMakeFiles/orrible.dir/orrible/main.cc.obj:main.cc:(.text+0x2a): undefined refer
ence to `_imp___ZN5boost6threadD1Ev'
collect2: ld returned 1 exit status
make[2]: *** [orrible.exe] Error 1
make[1]: *** [CMakeFiles/orrible.dir/all] Error 2
make: *** [all] Error 2
"

Making with VERBOSE=1, we see the command line:

"
C:\Compilers\MinGW\bin\g++.exe     -Wl, at CMakeFiles\orrible.dir\objects1.rsp  -o
orrible.exe -Wl,--out-implib,liborrible.dll.a -Wl,--major-image-version,0,--mino
r-image-version,0  C:\Compilers\Libs\libboost_thread-mgw44-mt-1_44.a -lkernel32
- -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladv
api32
"

Oddly enough, it links without complaint if I manually change the
command line to:

"
C:\Compilers\MinGW\bin\g++.exe
- -Wl, at CMakeFiles\orrible.dir\objects1.rsp  -oorrible.exe
- -Wl,--out-implib,liborrible.dll.a
- -Wl,--major-image-version,0,--minor-image-version,0 -LC:\Compilers\Libs
- -lboost_thread-mgw44-mt-1_44 -lkernel32 -luser32 -lgdi32 -lwinspool
- -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
"

(That is, if I manually separate
"C:\Compilers\Libs\libboost_thread-mgw44-mt-1_44.a" into
"-LC:\Compilers\Libs -lboost_thread-mgw44-mt-1_44".)

Is there a way to have CMake do this by itself and not use absolute
paths? I've tried setting CMP0003 to OLD but it doesn't seem to do that.

Thanks,
Adam J Richardson
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkzO7NQACgkQSUH6dLOqvqmM5QCgwAD9sffVFYn5/XxBD0t2KqxL
f7YAn0iOmlQ1C4OAvo/NiTVcN/Ox6sNX
=pzU7
-----END PGP SIGNATURE-----


More information about the CMake mailing list