首页 文章

使用Qt和Boost时的链接器错误

提问于
浏览
7

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

这是错误消息:

... obj:错误LNK2001:未解析的外部符号“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:错误LNK2001:未解析的外部符号“void __cdecl boost :: filesystem3 :: path_traits :: convert(char const *,char const *,class std :: basic_string ,类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 :: 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:错误LNK2001:un已解析的外部符号“void __cdecl boost :: filesystem3 :: path_traits :: convert(unsigned short const *,unsigned short const *,class std :: basic_string,class std :: allocator>&,class std :: codecvt const&)” (?转换@ path_traits @ filesystem3 @升压@@ YAXPBG0AAV?$ @的basic_string杜?$ @ char_traits @ d @@性病V'$ @分配器@ d @@ 2性病@@ ABV?$ @的codecvt GDH @ 5 @@ž )... exe:致命错误LNK1120:4个未解析的外部

EDIT:

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

这确实是一个Qt问题 . 使用wchar_t作为本机类型,您必须使用相同的编译器开关重新编译Qt . 跟踪器中甚至存在一个错误:https://bugreports.qt.io/browse/QTBUG-9617通常,您必须非常小心,不要在项目中混合使用wchar_t编译器设置,因为它们将变得不兼容 .

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

3 回答

  • 2

    我认为你走在正确的轨道上,但听起来像是 -Zc:wchar_t 没有"stick."我们不得不做同样的事情让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 以确保使用新设置真正重建所有内容 .

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

  • 8

    使用boost-1.49,Qt 4.4和VS2005也有同样的问题 . 转到项目属性,然后将“配置属性 - > C / C - >语言 - >将wchar_t视为内置类型”设置为“是”修复了问题 .

  • 0

    Qt可能改变了程序的脚本关于运行时的配置:因此,您使用的boost库(文件系统),通过命名约定访问许多配置 - 无法找到 .

    例如,多线程运行时需要mt在库名中的某个位置(我希望我记得很清楚,但无论如何都要查看完整记录详细信息的文档) . 这个命名对于程序员来说是相当透明的,因为pragma可以帮助程序员适当地使用它来简化不同编译器下的库使用 .

    你应该错过非wchar filesystem.lib . 当我使用Windows时,我使用boost Jam与Visual C接口(可能会回到过去的千年!) . 我希望它仍然有用 .

相关问题