Isn't there a static library for the unit-testing also: libboost_test_exec_monitor-xgcc42-mt-1_39 which also needs to be linked. That library is only static so it may not be picked up by the -DBOOST_TEST_DYN_LINK flag. For my unit testing I usually have the following:
SET (TEST_Boost_LIBS ${Boost_TEST_EXEC_MONITOR_LIBRARY} ) ADD_EXECUTABLE(MXAFileReaderWriterTest ${FILEREADERWRITER_TEST_SRCS}) TARGET_LINK_LIBRARIES (MXAFileReaderWriterTest ${TEST_Boost_LIBS} ) ADD_TEST(MXAFileReaderWriterTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MXAFileReaderWriterTest) Hope that helps. Also, are you manually finding the boost installation or using the FindPackage. Something like: # ---------- Find Boost Headers/Libraries ----------------------- SET (Boost_FIND_REQUIRED TRUE) SET (Boost_FIND_QUIETLY TRUE) set (Boost_USE_MULTITHREADED TRUE) set (Boost_USE_STATIC_LIBS TRUE) SET (Boost_ADDITIONAL_VERSIONS "1.39" "1.39.0") if ( NOT MXA_BOOST_HEADERS_ONLY) set (MXA_BOOST_COMPONENTS program_options unit_test_framework test_exec_monitor) endif() FIND_PACKAGE(Boost COMPONENTS ${MXA_BOOST_COMPONENTS} ) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) _________________________________________________________ Mike Jackson mike.jack...@bluequartz.net On Sat, Oct 3, 2009 at 9:31 AM, motes motes <mort.mo...@gmail.com> wrote: > I am trying to build an application with CMake using Boost and the > boost unit-testing framework in Ubuntu 9.04. I have installed boost > from synaptic. Here is what I have in my CMakeList.txt file: > > > IF(Boost_unit_test_framework_LIBRARY) > > GET_FILENAME_COMPONENT(LIB_EXTENSION ${Boost_unit_test_framework_LIBRARY} > EXT) > > IF(LIB_EXTENSION STREQUAL ".so") > > ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK) > > ENDIF(LIB_EXTENSION STREQUAL ".so") > > ENDIF(Boost_unit_test_framework_LIBRARY) > > > SUBDIRS(mytests) > > > > FIND_PATH(BOOST_LIB REQUIRED) > # Eg. /usr/include/boost > > INCLUDE_DIRECTORIES(${BOOST_LIB}) > > ------------------------------------------------------------------------------------------------------------------------ > > And there is the content of my unit test .cpp file: > > > > #define BOOST_AUTO_TEST_MAIN > #include <boost/test/auto_unit_test.hpp> > > // Boost Test declaration and Checking macros > #include <boost/test/unit_test_suite.hpp> > #include <boost/test/test_tools.hpp> > #include <boost/test/floating_point_comparison.hpp> > > BOOST_AUTO_TEST_SUITE(first_test); > BOOST_AUTO_TEST_SUITE(); > > > > BOOST_AUTO_TEST_CASE(first_test) > { > > > } > > > BOOST_CHECK_EQUAL(2,2); > > } > > > BOOST_AUTO_TEST_SUITE_END(); > > BOOST_AUTO_TEST_CASE(my_always_fail_test_case) > { > BOOST_CHECK(false); > } > > > > BOOST_AUTO_TEST_SUITE_END(); > > ------------------------------------------------------------------------------------------------------------------------ > > > But when I run make I get a long series of errors: > > /usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o: In > function `_start': > /build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: > undefined reference to `main' > CMakeFiles/unit_test_first_test.dir/src/unit_test_first_test.cpp.o: In > function `first_test::my_always_fail_test_case::test_method()': > unit_test_first_test.cpp:(.text+0x99): undefined reference to > `boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char > const>, unsigned long, boost::unit_test::basic_cstring<char const>)' > unit_test_first_test.cpp:(.text+0x13c): undefined reference to > `boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result > const&, boost::unit_test::lazy_ostream const&, > boost::unit_test::basic_cstring<char const>, unsigned long, > boost::test_tools::tt_detail::tool_level, > boost::test_tools::tt_detail::check_type, unsigned long, ...)' > CMakeFiles/unit_test_first_test.dir/src/unit_test_first_test.cpp.o: In > function `global constructors keyed to _Z20init_unit_test_suiteiPPc': > unit_test_first_test.cpp:(.text+0x27b): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char > const>)' > unit_test_first_test.cpp:(.text+0x29f): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char > const>)' > unit_test_first_test.cpp:(.text+0x304): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, > unsigned long)' > unit_test_first_test.cpp:(.text+0x31c): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(int)' > unit_test_first_test.cpp:(.text+0x37f): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, > unsigned long)' > unit_test_first_test.cpp:(.text+0x398): undefined reference to > `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(int)' > CMakeFiles/unit_test_first_test.dir/src/unit_test_first_test.cpp.o: In > function > `boost::unit_test::singleton<boost::unit_test::unit_test_log_t>::instance()': > unit_test_first_test.cpp:(.text._ZN5boost9unit_test9singletonINS0_15unit_test_log_tEE8instanceEv[boost::unit_test::singleton<boost::unit_test::unit_test_log_t>::instance()]+0x2c): > undefined reference to `vtable for boost::unit_test::unit_test_log_t' > CMakeFiles/unit_test_first_test.dir/src/unit_test_first_test.cpp.o: In > function > `boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> > const&, boost::unit_test::basic_cstring<char const>)': > unit_test_first_test.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> > const&, boost::unit_test::basic_cstring<char const>)]+0x1f): undefined > reference to > `boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char > const>)' > unit_test_first_test.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> > const&, boost::unit_test::basic_cstring<char const>)]+0x55): undefined > reference to > `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char > const>, boost::unit_test::callback0<boost::unit_test::ut_detail::unused> > const&)' > collect2: ld returned 1 exit status > make[2]: *** [revised/first_test/unit_test_first_test] Error 1 > make[1]: *** [revised/first_test/CMakeFiles/unit_test_first_test.dir/all] > Error 2 > make: *** [all] Error 2 > > > Any ideas on how to make boost unit test work with cmake? > _______________________________________________ > Powered by www.kitware.com > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Follow this link to subscribe/unsubscribe: > http://www.cmake.org/mailman/listinfo/cmake > _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake