执行 Boost 库时出现问题

执行 Boost 库时出现问题

我是 ubuntu 和 Boost 的新手。我安装了 ubuntu 11.10,并按照网站 (http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/) 上的说明尝试 BOOST 单元测试。我安装了 boost 库,并按照第 3 部分复制代码并尝试执行它,但执行时出现错误。

8w6Wa.o: In function `init_unit_test()':
bTest.cpp:(.text+0x51): undefined reference to
`boost::unit_test::framework::master_test_suite()'
/tmp/ccZ8w6Wa.o: In function `main':
bTest.cpp:(.text+0x9f): undefined reference to
`boost::unit_test::unit_test_main(bool (*)(), int, char**)'
/tmp/ccZ8w6Wa.o: In function `universeInOrder::test_method()':
bTest.cpp:(.text+0x121): undefined reference to
`boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char
const>, unsigned int, boost::unit_test::basic_cstring<char const>)'
bTest.cpp:(.text+0x1e3): 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 int, boost::test_tools::tt_detail::tool_level,
boost::test_tools::tt_detail::check_type, unsigned int, ...)'
/tmp/ccZ8w6Wa.o: In function `__static_initialization_and_destruction_0(int, int)':
bTest.cpp:(.text+0x2ea): undefined reference to
`boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*,
unsigned long)'
/tmp/ccZ8w6Wa.o: In function `boost::unit_test::unit_test_log_t::unit_test_log_t()':
bTest.cpp:(.text._ZN5boost9unit_test15unit_test_log_tC2Ev[_ZN5boost9unit_test15unit_test_log_tC5Ev]+0x21):
undefined reference to `vtable for boost::unit_test::unit_test_log_t'
/tmp/ccZ8w6Wa.o: In function
`boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused>
c    onst&, boost::unit_test::basic_cstring<char const>)':
bTest.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>)]+0x1d): undefined reference to
`boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char
const>)'
bTest.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>)]+0x5d): 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&)'
/tmp/ccZ8w6Wa.o: In function `boost::unit_test::unit_test_log_t::~unit_test_log_t()':
bTest.cpp:(.text._ZN5boost9unit_test15unit_test_log_tD2Ev[_ZN5boost9unit_test15unit_test_log_tD5Ev]+0xb):
undefined reference to `vtable for boost::unit_test::unit_test_log_t'
collect2: ld returned 1 exit status

我也尝试安装 sudo apt-get install libboost-dev-all,仍然出现同样的错误。

请帮我解决这个问题。提前谢谢。

答案1

我得到了解决方案,它的命令顺​​序,而不是使用

g++ -o hello -lboost_unit_test_framework hello.cpp(在早期版本中可以使用)

将其更改为

g++ -o hello hello.cpp -lboost_unit_test_framework

这很好用。

我提到https://stackoverflow.com/questions/7755668/linking-against-boost-thread-fails-under-ubuntu-11-10

相关内容