[CMake] Linking against boost_Test fails
Michael Hertling
mhertling at online.de
Mon Jun 21 15:19:02 EDT 2010
On 06/21/2010 04:53 PM, Oswin Krause wrote:
> Hello everybody,
>
> I am currently trying to write a cmake script for my testcases. Previously i used a command like this:
>
> g++ test.cpp -lboost_test_exec_monitor-mt -L/path/to/lib/ -lshark -I/path/to/include
>
> and everything worked fine.
> Now i'm using the following macro:
>
> MACRO( SHARK_ADD_TEST SRC NAME)
>
> ADD_EXECUTABLE( ${NAME}
> ${SRC}
> )
>
> SET( LINK_LIBRARIES
> ${Boost_TEST_EXEC_MONITOR_LIBRARY}
> shark
> )
> TARGET_LINK_LIBRARIES( ${NAME} ${LINK_LIBRARIES} )
>
> ADD_TEST( ${NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Test/${NAME} )
> ENDMACRO()
> SHARK_ADD_TEST( LinAlg/test.cpp LinAlg_test )
>
> And this creates the following commands:
> /usr/bin/c++ -D_CRT_SECURE_NO_WARNINGS -DBOOST_ALL_DYN_LINK -I/path/to/include -o /some/path/test.o -c path/to/test/test.cpp
>
> /usr/bin/c++ /some/path/test.o -o /path/to/bin -rdynamic -Wl,-Bstatic -lboost_test_exec_monitor-mt
> -Wl,-Bdynamic /path/to/lib/libshark.so.2.3.0 -Wl,-rpath,/path/to/lib
>
> and the error:
> undefined reference to 'boost::unit_test::unit_test_main(bool (*)(),int,char**)'
>
> So cmake finds the correct library, but seems to link wrong.
> How can i fix that?
Usually, this means you have a reference of your libshark.so.2.3.0 to
libboost_test_exec_monitor-mt.a, but in this case, your manually set up
link line wouldn't work, too, so are you sure that line works as you've
presented it, i.e. with -lboost_test_exec_monitor-mt before -lshark?
Does SET(LINK_LIBRARIES shark ${Boost_TEST_EXEC_MONITOR_LIBRARY}),
i.e. shark-before-boost, work?
Another potential cause for such incidents is the use of different C++
compiler versions, so do you have multiple compilers installed, or do
you have multiple Boost installations, and how does libshark.so.2.3.0
get built?
Regards,
Michael
More information about the CMake
mailing list