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