[CMake] Problems with CMake and Boost in Ubuntu 9.04
motes motes
mort.motes at gmail.com
Sat Oct 3 09:31:37 EDT 2009
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?
More information about the CMake
mailing list