Boost, Windows, and QtCreator

Boost, Windows, and QtCreator

本文关键字:QtCreator and Windows Boost      更新时间:2023-10-16

我在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:boostboost_1_57_0stagelib) -llibboost_timer-vc120-mt-1_57 -llibboost_system-vc120-mt-1_57
include(deployment.pri)
qtcAddDeployment()

现在,我在libs上尝试了很多变体,"define"是最近才出现的,但每次都会遇到未解决的符号问题:

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:boostboost_1_57_0stageliblibboost_timer-vc120-mt-1_57.lib:
Searching C:boostboost_1_57_0stageliblibboost_system-vc120-mt-1_57.lib:
Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64msvcprtd.lib:
Searching C:boostboost_1_57_0stageliblibboost_timer-vc120-mt-gd-1_57.lib:
Searching C:boostboost_1_57_0stageliblibboost_chrono-vc120-mt-gd-1_57.lib:
Searching C:boostboost_1_57_0stageliblibboost_system-vc120-mt-gd-1_57.lib:
Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64MSVCRTD.lib:
Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64OLDNAMES.lib:
Finished searching libraries
Finished pass 1

Searching libraries
    Searching C:boostboost_1_57_0stageliblibboost_timer-vc120-mt-1_57.lib:
    Searching C:boostboost_1_57_0stageliblibboost_system-vc120-mt-1_57.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64msvcprtd.lib:
    Searching C:boostboost_1_57_0stageliblibboost_timer-vc120-mt-gd-1_57.lib:
    Searching C:boostboost_1_57_0stageliblibboost_chrono-vc120-mt-gd-1_57.lib:
    Searching C:boostboost_1_57_0stageliblibboost_system-vc120-mt-gd-1_57.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64MSVCRTD.lib:
      Found _load_config_used
        Loaded MSVCRTD.lib(loadcfg.obj)
    Searching C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64OLDNAMES.lib:
    Searching C:Program Files (x86)Windows Kits8.1libwinv6.3umx64kernel32.lib:

Unused libraries:
  C:boostboost_1_57_0stageliblibboost_timer-vc120-mt-1_57.lib
  C:boostboost_1_57_0stageliblibboost_system-vc120-mt-1_57.lib
  C:boostboost_1_57_0stageliblibboost_timer-vc120-mt-gd-1_57.lib
  C:boostboost_1_57_0stageliblibboost_chrono-vc120-mt-gd-1_57.lib
  C:boostboost_1_57_0stageliblibboost_system-vc120-mt-gd-1_57.lib
  C:Program Files (x86)Microsoft Visual Studio 12.0VCLIBamd64OLDNAMES.lib

因此,它清楚地定位并查看了.lib文件,甚至注意到了我所要求的额外的lib包含,但没有定位要链接的代码对象。

可能与Windows 64有关?我以为boost会在这里构建为x64,但可能不是。有人建议尝试预构建的二进制文件,并会查找它们。

事实证明,我对Boost在windows下的构建过程假设太多了,需要告诉它是否在64位机器上。将库重新构建为64位,现在编译得很好。

谢谢大家的建议。