使用 Qt 和 Boost 时出现链接器错误
当我在我的 c++ 项目中同时使用 Qt (v4.7.4) 和 Boost(尝试过 v1.47 和 v1.48)时,我收到由包含
。我刚刚设置了 Qt,然后代码就可以正常工作了。
这是错误消息:
...obj:错误 LNK2001:无法解析的外部符号“私有:静态类 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 : 错误 LNK2001: 无法解析的外部符号 "void __cdecl boost::filesystem3::path_traits::convert(char const *,char const *,class std::basic_string,class std::allocator > & ;,类 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 : 错误 LNK2001: 无法解析的外部符号 "void __cdecl boost::filesystem3::path_traits::dispatch(class boost::filesystem3::directory_entry const &,class std::basic_string,class std::分配器 >,类 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 : 错误 LNK2001: 无法解析的外部符号 "void __cdecl boost::filesystem3::path_traits::convert(unsigned Short const *,unsigned Short const *,class std::basic_string,class std::allocator > ; &,类 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:致命错误 LNK1120:4 个无法解析的外部
编辑:
这里我发现有人遇到这个问题得出这样的结论:
这确实是一个 Qt 问题。使用 wchar_t 作为本机类型,您必须 使用相同的编译器开关重新编译 Qt。甚至还有一个错误 跟踪器:https://bugreports.qt.io/browse/QTBUG-9617< /p>
一般来说,你必须非常小心,不要混合 wchar_t 您项目中的编译器设置将变得不兼容。
于是我重新编译Qt设置/Zc:wchar_t
,但是没有显示任何效果。我仍然遇到同样的错误。
When I am using Qt (v4.7.4) and Boost (tried v1.47 and v1.48) together in my c++ project, I get a linker error caused by a class that includes <boost\filesystem.hpp>
. I just set up Qt and before the code was working without any problems.
This is error message:
...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
EDIT:
Here I found someone having this problem coming to this conclusion:
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-9617In general, you will have to be very careful and do not mix wchar_t
compiler settings in your projects as they will become incompatible.
So I recompiled Qt setting /Zc:wchar_t
, but it didn't show any effect. I still get the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您走在正确的轨道上,但听起来您的
-Zc:wchar_t
并没有“坚持”。我们必须做同样的事情才能让 Qt 满意 Google Breakpad 和 ICU 库。我们更改了(QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf
中的/Zc:wchar_t
设置并从源代码编译了 Qt,之后一切正常。当您构建使用 Qt 和 Boost 的项目时,您应该在编译器输出中看到此选项。例如:
如果您已经在没有此选项的情况下构建了 Qt,则可能必须首先执行
make confclean
以确保所有内容都真正使用新设置重新构建。听起来 -Zc:wchar_t 将成为 Qt 5 中的默认值。
I think you are on the right track, but it sounds like your
-Zc:wchar_t
didn't "stick." We had to do the same thing to make Qt happy with Google Breakpad and the ICU library. We changed the/Zc:wchar_t
setting in(QT_SOURCE)\mkspecs\win32-msvc2008\qmake.conf
and compiled Qt from source, and after that everything works.When you build your project that uses Qt and Boost, you should see this option in the compiler output. Something like:
If you've already build Qt without this option, you may have to do a
make confclean
first to ensure everything really gets rebuilt with the new settings.It sounds like -Zc:wchar_t will be the default in Qt 5.
使用boost-1.49,Qt 4.4和VS2005也有同样的问题。转到项目属性,然后将“配置属性 -> C/C++ -> 语言 -> 将 wchar_t 作为内置类型”设置为“是”解决了该问题。
Using boost-1.49, Qt 4.4 and VS2005 had the same problem. Going to project properties, then setting "Configuration Properties -> C/C++ -> Language -> Treat wchar_t as Built-in Type" to "Yes" fixed the problem.
Qt 可能改变了程序在运行时配置方面的结构:因此,您使用的 boost 库(文件系统)存在于通过命名约定访问的许多配置中 - 无法找到。
例如,多线程运行时需要库名称中的某处mt(我希望我记得很好,但无论如何请参阅详细记录了详细信息的文档)。这种命名对于程序员来说是相当透明的,因为编译指示可以适当地使用增强程序员来简化不同编译器下的库使用。
您应该错过非 wchar filesystem.lib。当我使用 Windows 时,我使用 boost Jam 与 Visual C++ 交互(可能可以追溯到过去的千年!)。我希望它还能用。
Qt probably changed the tipology of your program with regards the configuration of the runtime: consequently, the boost library you use (filesystem), that come in many configuration accessed by naming convention - connot be found.
For instance, multithread runtimes require mt somewhere in library name (I hope I remember well, but anyway see the docs where details are fully documented). This naming is fairly transparent to the programmer, due to pragmas that boost programmers appropriately used to ease the library usage under different compilers.
You should miss the non-wchar filesystem.lib. When I used Windows, I used boost Jam to interface with Visual C++ (may be that goes back to the past millenium!). I hope it's still usable.