我想通过Eclipse编译以下代码行,但在构建时我会得到错误,我无法理解..是否有任何人有解决方案来解决它。
#include <boost/test/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_MODULE First_TestSuite
BOOST_AUTO_TEST_CASE( First_TEst )
{
BOOST_CHECK(2 == 2);
}
错误
12:55:13 ****增量构建配置项目调试 NewProject ****信息:内部构建器用于构建g ++ “-IC:\ boost_1_52_0 \ boost_1_52_0”-O0 -g3 -Wall -c -fmessage-length = 0 -o“src \ NewProject.o”“.. \ src \ NewProject.cpp”g ++ -o NewProject.exe“src \ NewProject.o”src \ NewProject.o:In function
ZN10First_TEst11test_methodEv': C:\Users\sam\workspace1\NewProject\Debug/../src/NewProject.cpp:19: undefined reference to
boost :: unit_test :: unit_test_log_t :: set_checkpoint(boost :: unit_test :: basic_cstring,unsigned int,boost :: unit_test :: basic_cstring)' C:\用户\ SAM \工作空间1 \ NewProject \调试/../的src / NewProject.cpp:19: 未定义的引用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, ...)' src\NewProject.o: In function
_ static_initialization_and_destruction_0' : C:\用户\ SAM \工作空间1 \ NewProject \调试/../的src / NewProject.cpp:16: 未定义的引用boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)' src\NewProject.o: In function
ZN5boost9unit_test15unit_test_log_tC1Ev': C:/boost_1_52_0/boost_1_52_0/boost/test/unit_test_log.hpp:131: 未定义引用vtable for boost::unit_test::unit_test_log_t' src\NewProject.o: In function
ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE': C:/boost_1_52_0/boost_1_52_0/boost/test/unit_test_suite_impl.hpp:255: 未定义的引用boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)' C:/boost_1_52_0/boost_1_52_0/boost/test/unit_test_suite_impl.hpp:255: undefined reference to
的boost :: unit_test :: test_case :: test_case(升压:: unit_test :: basic_cstring, 提高:: unit_test :: callback0 const&amp;)'src \ NewProject.o:在函数中ZN5boost9unit_test15unit_test_log_tD1Ev': C:/boost_1_52_0/boost_1_52_0/boost/test/unit_test_log.hpp:93: undefined reference to
vtable for boost :: unit_test :: unit_test_log_t' C:/ MinGW的/ bin中/../ LIB / GCC /的mingw32 / 4.7.2 /../../../ libmingw32.a(main.o),此:main.c中:( text.startup + 0xa7)。 : 未定义引用`WinMain @ 16'colle2.exe:错误:ld返回1 退出状态12:55:24构建完成(耗时11s.567ms)
答案 0 :(得分:6)
好像你忘了添加-lboost_unit_test_framework-mt
或者在Windows系统中命名该库的任何内容
答案 1 :(得分:5)
如果您只想使用标题变体,则应包含以下内容
#define BOOST_TEST_MODULE First_TestSuite
#include <boost/test/included/unit_test.hpp>
代替你的
#include <boost/test/unit_test.hpp>
并且您只需要#define BOOST_TEST_MODULE First_TestSuite
仅包含标题变体。
答案 2 :(得分:1)
您应该使用Boost中的Single Header Variant of the UTF
。