【问题标题】:Boost, Windows, and QtCreatorBoost、Windows 和 QtCreator
【发布时间】:2015-03-04 05:47:11
【问题描述】:

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

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

ma​​in.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()

现在,我在库上尝试了很多变体,并且“定义”是最近的,但每次我都会遇到未解决的符号问题:

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,但也许不是。有人建议尝试预先构建的二进制文件,将看看它们。

【问题讨论】:

  • 您是否尝试从 pro 文件中删除 BOOST_ALL_NO_LIB
  • 没有区别;我刚才仔细检查了,但正如我所说,该定义是最近添加到 .pro 文件中的。
  • 您是否尝试过使用预构建的二进制文件?
  • 老兄。 “戏剧性的叙述”很好,但它分散了在 SO 上被问了几十次的问题
  • 使用的编译器是什么?上次我检查 cmake 并没有真正使这些东西正确吗?

标签: c++ windows boost qt-creator


【解决方案1】:

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

感谢大家的建议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    相关资源
    最近更新 更多