我正在使用 QT Creator 开发一个 boost 单元测试框架的项目。我已经编写了一个小测试程序并尝试链接 libboost_unit_test_framework-vc100-mt-gd-1_56.lib
。该库存在于指定路径中。但是程序无法编译并给出上述链接错误。
我在网上搜索了一下,发现错误应该是#define BOOST_ALL_NO_LIB
。但是,我遇到了以下错误:
main.obj:-1: error: LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite@@YAPAVtest_suite@unit_test@boost@@HQAPAD@Z) referenced in function _main
以上函数是libboost_unit_test_framework-vc100-mt-gd-1_56.lib
的一部分。
我使用 VS 2010 和相同的 boost 库编写了相同的单元测试。该程序按预期行为正常运行。
在 QT 上使用 boost 可能会出现什么问题?
最佳答案
您缺少测试模块初始化函数。在包含 UTF header 之前,您是否定义了 BOOST_TEST_MAIN
或 BOOST_TEST_MODULE
?
To automatically generate an empty test module initialization function you need to define BOOST_TEST_MAIN before including the boost/test/unit_test.hpp header. The value of this define is ignored. Alternatively you can define the macro BOOST_TEST_MODULE to be equal to any string (not necessarily in quotes). This macro causes the same result as BOOST_TEST_MAIN, and in addition the macro value becomes the name of the master test suite.
For a test module consisting of multiple source files you have to define these flags in a single test file only. Otherwise you end up with multiple instances of the initialization function.
更多信息在这里:http://www.boost.org/doc/libs/1_57_0/libs/test/doc/html/utf/user-guide/initialization.html
关于c++ - Boost 1.56 with QT creator, "LNK1104: cannot open file ' libboost_unit_test_framework-vc100-mt-gd-1_56.lib'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405921/