Boost、Windows 和 QtCreator
Boost, Windows, and QtCreator
我在 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()
现在,我已经尝试了很多库的变体,'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 导入哪些库...但这也不起作用。
编辑:
尝试为 linker 设置 /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.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 文件,甚至注意到我要求的库的额外包含,但没有找到 link 的代码对象。
可能与 Windows 64 岁有关?我假设 boost 会在这里构建为 x64,但也许不会。有人建议尝试预构建的二进制文件,看看它们。
好吧,事实证明我对 windows 下 Boost 的构建过程假设太多,如果它在 64 位机器上需要被告知。将库重建为 64 位,现在编译正常。
感谢大家的建议
我在 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()
现在,我已经尝试了很多库的变体,'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 导入哪些库...但这也不起作用。
编辑: 尝试为 linker 设置 /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.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 文件,甚至注意到我要求的库的额外包含,但没有找到 link 的代码对象。
可能与 Windows 64 岁有关?我假设 boost 会在这里构建为 x64,但也许不会。有人建议尝试预构建的二进制文件,看看它们。
好吧,事实证明我对 windows 下 Boost 的构建过程假设太多,如果它在 64 位机器上需要被告知。将库重建为 64 位,现在编译正常。
感谢大家的建议