c++ - 使用 Qt 和 Boost 时出现链接器错误

标签 c++ visual-studio-2010 qt boost linker-errors

当我在我的 C++ 项目中同时使用 Qt (v4.7.4) 和 Boost(尝试过 v1.47 和 v1.48)时,我收到一个由包含 <boost\filesystem.hpp> 的类引起的链接器错误.我刚刚设置了 Qt,在代码运行没有任何问题之前。

这是错误信息:

...obj : error LNK2001: unresolved external symbol "private: static class std::codecvt const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAAPBV?$codecvt@GDH@std@@XZ)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(char const *,char const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert@path_traits@filesystem3@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@5@@Z)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::dispatch(class boost::filesystem3::directory_entry const &,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?dispatch@path_traits@filesystem3@boost@@YAXABVdirectory_entry@23@AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@6@@Z)

...obj : error LNK2001: unresolved external symbol "void __cdecl boost::filesystem3::path_traits::convert(unsigned short const *,unsigned short const *,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (?convert@path_traits@filesystem3@boost@@YAXPBG0AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$codecvt@GDH@5@@Z)

...exe : fatal error LNK1120: 4 unresolved externals

编辑:

Here我发现有人遇到这个问题得出了这个结论:

this really is a Qt issue. Using wchar_t as a native type you have to recompile Qt using the same compiler switch. There even is a bug in the tracker: https://bugreports.qt.io/browse/QTBUG-9617

In general, you will have to be very careful and do not mix wchar_t compiler settings in your projects as they will become incompatible.

所以我重新编译了Qt设置/Zc:wchar_t ,但没有显示任何效果。我仍然遇到同样的错误。

最佳答案

我认为您走在正确的轨道上,但听起来您的 -Zc:wchar_t 没有“坚持”。我们必须做同样的事情才能使 Qt 对 Google Breakpad 和 ICU 库感到满意。我们更改了 (QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf 中的 /Zc:wchar_t 设置并从源代码编译 Qt,之后一切正常。

当您构建使用 Qt 和 Boost 的项目时,您应该会在编译器输出中看到此选项。像这样的东西:

cl -c -nologo -Zm200 -Zc:wchar_t ... (etc.)

如果您已经在没有此选项的情况下构建了 Qt,您可能必须先执行 make confclean 以确保使用新设置重建所有真正。 p>

听起来像-Zc:wchar_t will be the default in Qt 5 .

关于c++ - 使用 Qt 和 Boost 时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8196820/

相关文章:

c++ - 在 Eclipse 中从 C++ 调用 Ada

c++ - 嵌套模板类: Parameter default value not accepted

具有右值引用的 C++ 模板化方法消歧规则

visual-studio-2010 - MSB6006 : "CL.exe" exited with code 2

c++ - 错误 : type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'

c++ - 有人解释汇编语言级别的左值和右值吗?

visual-studio-2010 - Visual Studio 2010 SP1 无法安装

visual-studio-2010 - 每次构建前清除 "Error List"警告的 Visual Studio 2010 插件/代码

svn - 设置 qt creator 以在 windows 上使用 tortoise svn

c++ - QPainter 或 QLabel 绘制 QPixmap 的成本较低