QTCreator + MSVC10编译器 使用boost::filesystem 时 error LNK2019: codecvt ... 问题的解决

今天在将一个QTCreator管理的项目 从Linux下 拿到Windows 下(使用MSVC10编译器) 来编译时发现居然通不过。报了以下连接错误:

error LNK2019: 无法解析的外部符号 "public: static class std::codecvt<unsigned short,char,int> const & __cdecl boost::filesystem::path::codecvt(void)" (?codecvt@path@filesystem@boost@@SAABV?$codecvt@GDH@std@@XZ),该符号在函数 "public: class boost::filesystem::path & __thiscall boost::filesystem::path::operator/=<char const [5]>(char const (&)[5])" (??$?_0$$BY04$$CBD@path@filesystem@boost@@QAEAAV012@AAY04$$CBD@Z) 中被引用

main.obj : error LNK2019: 无法解析的外部符号 "void __cdecl boost::filesystem::path_traits::convert(char const *,char const *,class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &,class std::codecvt<unsigned short,char,int> const &)" (?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@5@@Z),该符号在函数 "void __cdecl boost::filesystem::path_traits::dispatch<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > &,class std::codecvt<unsigned short,char,int> const &)" (??$dispatch@V?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@path_traits@filesystem@boost@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@4@ABV?$codecvt@GDH@4@@Z) 中被引用


最开始怀疑是boost库路径 或者编译有问题,于是乎在VS2010下建了一个类似的demo进行类似测试,最终确认了不是库的问题,也不是代码的问题!


折腾了一下午,网上寻觅中发现有童鞋遇到个类似的问题,但是是在VS中遇到的问题的原因是:

     “vs没有默认wchar_t为内置的原因, 选择 项目 -> 属性->c/c++ -> 语言 -> 将wchar_t设为内置类型(是)”


然后我将刚才在VS2010下建的demo的工程的该属性修改“否”时,确实报了和在QTCreator中一模一样的错误。

查看了一下这两种情况下VS2010项目属性中C/C++的命令行里面分别为“/Zc:wchar_t”和“/Zc:wchar_t-”


问题找到了,转回QTCreator 在项目文件 “xx.pro”(其实我的是xxx.pri /偷笑)中添加以下内容:

    

win32:contains(QMAKE_CC, cl){
    QMAKE_CXXFLAGS += -Zc:wchar_t
}
 
Creator中重新构建项目的时候可以看到"编译输出 窗口"中有cl命令如下:

 
    "cl -c -nologo -Zm200 -Zc:wchar_t- -Zc:wchar_t "
 
 
刚才添加的 -Zc:wchar_t 被放置到了默认"-Zc:wchar_t-"的后面 。Link之前给了个红色提示:

     “cl: 命令行 warning D9025 :正在重写“/Zc:wchar_t-”(用“/Zc:wchar_t”)”
 
    当然如果再添加一条  QMAKE_CXXFLAGS -= -Zc:wchar_t-"就更好了
 
win32:contains(QMAKE_CC, cl){
    QMAKE_CXXFLAGS -= -Zc:wchar_t-
    QMAKE_CXXFLAGS += -Zc:wchar_t
}

 
构建通过,问题搞定。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值