c++ - Boost 1.56 with QT creator, "LNK1104: cannot open file ' libboost_unit_test_framework-vc100-mt-gd-1_56.lib'”

标签 c++ qt boost qt-creator qt5

我正在使用 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_MAINBOOST_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/

相关文章:

c++ - "Reloading"一个 boost 定时器绑定(bind)到一个类方法

c++ - 有没有办法禁止 C++ 中的指针比较?

python - 如何移动QLabel?

qt - 如何设置精度和对齐方式以在 QTableView 中显示数值

c++ - 我可以在头文件中#define QStringLiterals 吗?

c++ - 使用 qchecksum 而不是 boost crc16

c++ - 如何截断boost日志格式表达式

c++ - 不正确的排序和/或搜索通过外部文件填充的数组

c++ - Oracle最新OCI版本

c++从父类实例化 protected 成员