c++ - x64 上 Boost 1.60 和 VS 2013 的链接器错误

标签 c++ qt boost cmake

#include <iostream>
#include <boost/timer/timer.hpp>

int main()
{
    boost::timer::auto_cpu_timer s;
    std::cout << "Hello World!" << '\n';
    return 0;
}

使用 msvc 12.0 x64 在 qt 中编译上面提到的代码并抛出以下错误:

libboost_timer-vc120-mt-gd-1_60.lib(cpu_timer.obj) : error LNK2019: unresolved external symbol "public: static class boost::chrono::time_point<class boost::chrono::steady_clock,class boost::chrono::duration<__int64,class boost::ratio<1,1000000000> > > __cdecl boost::chrono::steady_clock::now(void)" (?now@steady_clock@chrono@boost@@SA?AV?$time_point@Vsteady_clock@chrono@boost@@V?$duration@_JV?$ratio@$00$0DLJKMKAA@@boost@@@23@@23@XZ) referenced in function "void __cdecl `anonymous namespace'::get_cpu_times(struct boost::timer::cpu_times &)" (?get_cpu_times@?A0x0d396f6a@@YAXAEAUcpu_times@timer@boost@@@Z)
debug\Test.exe : fatal error LNK1120: 1 unresolved externals

Boost 已在架构 x86 和地址模型 64 中使用以下命令行参数进行编译-

b2 toolset=msvc-12.0 --prefix=<location> --build-type=complete --abbreviate-paths architecture=x86 address-model=64 install -j4

此外,程序在使用 32 位 msvc 2013 编译器编译时运行良好,我使用的是 Qt Creator。这是我的项目文件的内容 -

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp


win32:CONFIG(release, debug|release): LIBS += "-LD:/boost/boost_1_60_0/stage/lib/" -llibboost_system-vc120-mt-1_60 -llibboost_filesystem-vc120-mt-1_60 -llibboost_timer-vc120-mt-1_60
else:win32:CONFIG(debug, debug|release): LIBS += "-LD:/boost/boost_1_60_0/stage/lib/" -llibboost_system-vc120-mt-gd-1_60 -llibboost_filesystem-vc120-mt-gd-1_60 -llibboost_timer-vc120-mt-gd-1_60
else:unix: LIBS += "-LD:/boost/boost_1_60_0/stage/lib/" -llibboost_system-vc120-mt-1_60 -llibboost_filesystem-vc120-mt-1_60 -llibboost_timer-vc120-mt-1_60 

INCLUDEPATH += D:/boost/boost_1_60_0/

最佳答案

我刚刚在 VS2015 中遇到了完全同样的问题。

我的解决方案是:

#include <boost/chrono.hpp>

希望这对其他人有帮助!

关于c++ - x64 上 Boost 1.60 和 VS 2013 的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214489/

相关文章:

c++ - 串行端口奇偶校验在 boost asio 中失败

c++ - 多态数据转换/转换设计模式

c++ - 关于使用 QThreadStorage 的线程安全

c++ - 如何获取 beast::flat_buffer 中的数据?

c++ - boost 图表。与继承等效的技术

c++ - 使用boost::thread的Actor计算模型

c++ - 在C++中实现链表的困难

c++ - 未绘制 QToolButton 上的文本

MySQL + Qt QMYSQL 插件 = 商业 MySQL 许可证?

c++ - 我如何使用 boost::thread::id 作为 unordered_map 的键?