c++ - Boost、Windows 和 QtCreator

标签 c++ windows boost qt-creator

我在 linux 下使用 boost 已经有一段时间了,但我很快就会在 Windows 项目上工作,所以我决定为 Windows 设置 Boost,并让它与 QtCreator 一起工作(也在 linux 下工作)。

所以,下载并构建了 windows boost 库,然后去 QtCreator 在 windows 下试用它们,我一直有些困惑。

main.cpp

#include <iostream>
#include <vector>

#include <boost/timer/timer.hpp>

using namespace std;

vector<int> f();

int main()
{
    cout << "Hello World!" << endl;

    vector<int> r;
    {
        boost::timer::auto_cpu_timer ct;
        r = f();
    }
    return 0;
}

vector<int> f() {
    vector<int> result;

    for (auto i = 0U; i < 10000; i++) {
        result.push_back(i);
    }
    return result;
}

test.pro

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

SOURCES += main.cpp

DEFINES += BOOST_ALL_NO_LIB
INCLUDEPATH+= C:/boost/boost_1_57_0/
LIBS += -L$$quote(C:\boost\boost_1_57_0\stage\lib) -llibboost_timer-vc120-mt-1_57 -llibboost_system-vc120-mt-1_57

include(deployment.pri)
qtcAddDeployment()

现在,我已经尝试了很多关于库的变体,并且“定义”是最近的,但每次,我都会遇到 Unresolved 符号问题:

main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat@system@boost@@YAXXZ)
main.obj : error LNK2019: unresolved external symbol "public: __cdecl boost::timer::auto_cpu_timer::auto_cpu_timer(short)" (??0auto_cpu_timer@timer@boost@@QEAA@F@Z) referenced in function main
main.obj : error LNK2019: unresolved external symbol "public: __cdecl boost::timer::auto_cpu_timer::~auto_cpu_timer(void)" (??1auto_cpu_timer@timer@boost@@QEAA@XZ) referenced in function main

现在,从我读到的内容来看,似乎我什至不必说明要从 boost 导入哪些库...但这也不起作用。

编辑: 尝试为链接器设置/VERBOSE 标志,这很奇怪;突出的部分是:

Referenced in kernel32.lib(KERNEL32.dll)
    Loaded kernel32.lib(KERNEL32.dll)
Searching C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-1_57.lib:
Searching C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-1_57.lib:
Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\msvcprtd.lib:
Searching C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-gd-1_57.lib:
Searching C:\boost\boost_1_57_0\stage\lib\libboost_chrono-vc120-mt-gd-1_57.lib:
Searching C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-gd-1_57.lib:
Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\MSVCRTD.lib:
Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\OLDNAMES.lib:

Finished searching libraries

Finished pass 1


Searching libraries
    Searching C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-1_57.lib:
    Searching C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-1_57.lib:
    Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\msvcprtd.lib:
    Searching C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-gd-1_57.lib:
    Searching C:\boost\boost_1_57_0\stage\lib\libboost_chrono-vc120-mt-gd-1_57.lib:
    Searching C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-gd-1_57.lib:
    Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\MSVCRTD.lib:
      Found _load_config_used
        Loaded MSVCRTD.lib(loadcfg.obj)
    Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\OLDNAMES.lib:
    Searching C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64\kernel32.lib:

Unused libraries:
  C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-1_57.lib
  C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-1_57.lib
  C:\boost\boost_1_57_0\stage\lib\libboost_timer-vc120-mt-gd-1_57.lib
  C:\boost\boost_1_57_0\stage\lib\libboost_chrono-vc120-mt-gd-1_57.lib
  C:\boost\boost_1_57_0\stage\lib\libboost_system-vc120-mt-gd-1_57.lib
  C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64\OLDNAMES.lib

因此,很明显它找到并查看了 .lib 文件,甚至注意到我要求的库的额外包含,但没有找到要链接的代码对象。

可能与使用 Windows 64 有关?我假设 boost 会在这里构建为 x64,但也许不会。有人建议尝试预构建的二进制文件,看看它们。

最佳答案

好吧,事实证明我对 Windows 下 Boost 的构建过程假设太多,如果它在 64 位机器上需要被告知。将库重建为 64 位,现在编译正常。

感谢大家的建议。

关于c++ - Boost、Windows 和 QtCreator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28847423/

相关文章:

c# - 终止在 C# 中运行消息循环的工作线程

windows - 如何制作只显示文本文件最后一行的批处理脚本?

c++ - std::tuple 和 boost::tuple 之间的转换

c++ - 使用 std::tuple 作为 std::unordered_map 的键

c++ - 以实参作为模板形参的模板化函数指针

c++ - 动画围绕特定轴的 qt3d 旋转

c++ - 链接 Windows C++ 项目以 boost 命令行体系结构类型问题

c++ - 在 C++ 中编写通用堆栈类

python - 无法启动用 Python 编写的 Windows 服务(win32serviceutil)

c++ - boost::lockfree::spsc_queue、boost::lockfree::queue、串行队列操作之间的比较