1

我正在尝试通过构建一个独立的库来使用 Boost Unit Test Framework,如下所述:

http://www.boost.org/doc/libs/1_35_0/libs/test/doc/components/utf/compilation.html

所以我创建了一个包含上述文件的 VC 库项目并构建它,它成功了。然后我创建了一个测试项目并引用了我刚刚创建的库项目,但是当我尝试构建它时,我得到了以下链接错误:

1>Type.obj : error LNK2019: unresolved external symbol "bool __cdecl boost::test_tools::tt_detail::check_impl(class boost::test_tools::predicate_result const &,class boost::unit_test::lazy_ostream const &,class boost::unit_test::basic_cstring<char const >,unsigned __int64,enum boost::test_tools::tt_detail::tool_level,enum boost::test_tools::tt_detail::check_type,unsigned __int64,...)" (?check_impl@tt_detail@test_tools@boost@@YA_NAEBVpredicate_result@23@AEBVlazy_ostream@unit_test@3@V?$basic_cstring@$$CBD@63@_KW4tool_level@123@W4check_type@123@3ZZ) referenced in function "public: void __cdecl test1::test_method(void)" (?test_method@test1@@QEAAXXZ)
1>BoostUnitTestFramework.lib(framework.obj) : error LNK2019: unresolved external symbol "void __cdecl boost::debug::break_memory_alloc(long)" (?break_memory_alloc@debug@boost@@YAXJ@Z) referenced in function "void __cdecl boost::unit_test::framework::init(class boost::unit_test::test_suite * (__cdecl*)(int,char * * const),int,char * * const)" (?init@framework@unit_test@boost@@YAXP6APEAVtest_suite@23@HQEAPEAD@ZH0@Z)
1>BoostUnitTestFramework.lib(framework.obj) : error LNK2019: unresolved external symbol "void __cdecl boost::debug::detect_memory_leaks(bool)" (?detect_memory_leaks@debug@boost@@YAX_N@Z) referenced in function "void __cdecl boost::unit_test::framework::init(class boost::unit_test::test_suite * (__cdecl*)(int,char * * const),int,char * * const)" (?init@framework@unit_test@boost@@YAXP6APEAVtest_suite@23@HQEAPEAD@ZH0@Z)
1>BoostUnitTestFramework.lib(execution_monitor.obj) : error LNK2019: unresolved external symbol "bool __cdecl boost::debug::attach_debugger(bool)" (?attach_debugger@debug@boost@@YA_N_N@Z) referenced in function "public: int __cdecl boost::detail::system_signal_exception::operator()(unsigned int,struct _EXCEPTION_POINTERS *)" (??Rsystem_signal_exception@detail@boost@@QEAAHIPEAU_EXCEPTION_POINTERS@@@Z)
1>BoostUnitTestFramework.lib(execution_monitor.obj) : error LNK2019: unresolved external symbol "bool __cdecl boost::debug::under_debugger(void)" (?under_debugger@debug@boost@@YA_NXZ) referenced in function "public: int __cdecl boost::execution_monitor::execute(class boost::unit_test::callback0<int> const &)" (?execute@execution_monitor@boost@@QEAAHAEBV?$callback0@H@unit_test@2@@Z)
1>BoostUnitTestFramework.lib(unit_test_main.obj) : error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite@@YAPEAVtest_suite@unit_test@boost@@HQEAPEAD@Z) referenced in function main
1>C:\Users\Rafid\Workspace\MyPhysics\Builds\VC10\Tests\Debug\Tests.exe : fatal error LNK1120: 6 unresolved externals

它们似乎主要是由 Boost 调试库引起的,但我看不出我应该得到链接错误的原因,因为 Boost 调试库只需要作为头文件包含,而不是作为库链接!

有任何想法吗?!

4

2 回答 2

2

好的,我弄清楚了问题所在。显然,Boost 网站中提到的文件列表缺少以下文件:

debug.cpp
test_main.cpp
test_tools.cpp

一旦我将这些文件添加到我的项目中,测试项目就编译并成功运行!

更新:只是想提一下我实际上是针对 Boost 1.51 构建的,所以文档可能有点旧,因为我可以在页面中看到,他们将文件链接到 Boost 1.35!

于 2012-09-04T21:36:23.240 回答
0

为了在 Windows 上编译 boots 1.57 的单元测试,
我使用@Rafid答案,
对我来说,它是将这些文件添加到项目中:

test_tools.cpp
unit_test_main.cpp
framework.cpp

位于BOOST_DIR/libs/test/src

于 2015-11-25T22:12:08.090 回答