Boost,Windows和QtCreator

时间:2015-03-04 05:47:12

标签: c++ windows boost qt-creator

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

所以,下载并构建了windows boost libs并前往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()

现在,我已尝试了很多关于libs和&#39;定义&#39;是最近的,但每次,我都会得到未解决的符号问题:

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

现在,从我所读过的内容来看,似乎我不应该甚至不必说明从哪个库中导入...但这也不起作用。

编辑: 尝试为链接器设置/ 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文件,甚至注意到我要求的libs的额外包含,但没有找到要链接的代码对象。

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

1 个答案:

答案 0 :(得分:1)

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

感谢民间的建议。