[CMake] Linking against boost_Test fails

Oswin Krause oswinKrause at web.de
Mon Jun 21 16:19:24 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?
Yes, it is exactly this:
g++ cblnsrch.cpp -lboost_test_exec_monitor-mt 
-L/home/oswin/Projekte/Shark/shark-project/branches/SharkReworkBoostRng/Shark/lib/ -lshark 
-I/home/oswin/Projekte/Shark/shark-project/branches/SharkReworkBoostRng/Shark/include/

But there is  currently no dependency between shark and boost, so the order shouldn't make a difference.

>Does SET(LINK_LIBRARIES shark ${Boost_TEST_EXEC_MONITOR_LIBRARY}),
>i.e. shark-before-boost, work?
Same result, unfortunately.

>
>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?
I'm building the tests with the same cmake Script as i'm currently trying to build the Tests.
I checked the gcc versions. My gcc was quite old, 4.4.1 and boost was build with 4.4.3. But updating gcc to 4.4.5 didn't help either.
And both are now the newest version of my distribution. 
>
>Regards,
>
>Michael
Thanks for your tips.

Regards,
Oswin


More information about the CMake mailing list