懒得打字

懒得打字

使用Qt的qmake管理boost::filesystem代码时出现LNK2019问题

使用QT管理包含有BOOST的代码会出现种种问题,下面的代码使用qmake创建的vcproj编译通过了

    string dir_name = sec_log_namespace::logfile_name;
    boost::filesystem::path logFilePath(dir_name);
    boost::filesystem::path logFileDir = logFilePath.parent_path();
    if (!boost::filesystem::exists(logFileDir)) {
        boost::filesystem::create_directory(logFileDir);
    }

但是链接时出错:

1>sec_log.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) 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 &)" (__imp_?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ABV?$codecvt@GDH@5@@Z) referenced in function "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> > &)" (?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>sec_log.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::codecvt<unsigned short,char,int> const & __cdecl boost::filesystem::path::codecvt(void)" (__imp_?codecvt@path@filesystem@boost@@SAABV?$codecvt@GDH@std@@XZ) referenced in function "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> > &)" (?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)

把上面代码放到单独创建的vc工程中,发现没有问题,能编译,能链接。于是怀疑是编译环境问题,比较cl的command line,发现有个-Zc:wchar_t的选项。查了stackflow发现也是字符类型的问题,于是测试

打开vs中的Project->Properites,选择Configuration Properties->C/C++->Language->Treat wchar_t as Build-in type改成Yes。OK,链接成功。

然后改pro文件,加上下面一段:

    win32:contains(QMAKE_CC, cl){
        QMAKE_CXXFLAGS += -Zc:wchar_t
    }



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lonelysky/article/details/52351770
个人分类: C++ QT
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭