【发布时间】:2012-02-08 18:47:55
【问题描述】:
您好,我正在使用 Visual Studio 2010。我为 Qt 添加了插件,并手动构建了最后一个 boost 包。现在我开始了一个新项目,一个qt窗口应用程序。
我使用了以下代码:
#include <boost/filesystem.hpp>
int main(int argc, char *argv[])
{
boost::filesystem::path p("c:/test/test.gmx");
boost::filesystem::path ext(p.extension());
boost::filesystem::path name(p.leaf().replace_extension(""));
//QApplication a(argc, argv);
//MainInterface w;
//w.show();
//return a.exec();
}
但是这似乎失败了。当我使用完全相同的代码但不使用 qt 模板时,它可以工作。具体错误如下:
1>main.obj : error LNK2019: unresolved external symbol "private: static class std::codecvt<unsigned short,char,int> const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAAPBV?$codecvt@GDH@std@@XZ) referenced in function "public: static class std::codecvt<unsigned short,char,int> const & __cdecl boost::filesystem3::path::codecvt(void)" (?codecvt@path@filesystem3@boost@@SAABV?$codecvt@GDH@std@@XZ)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl boost::filesystem3::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@filesystem3@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::filesystem3::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@filesystem3@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库目录仍然位于VC++目录下->库目录
这是什么原因造成的?我该如何解决?
【问题讨论】:
-
您不仅需要 boost::filesystem 的目录,还需要链接 boost_filesystem 库。你有那一套吗? (而且 Qt 有文件/路径管理功能,你应该在 Qt 项目中使用这些功能。)
-
@Mat 你的意思是什么?如果您的意思是我必须在附加依赖项部分包含实际库。我怎么知道实际库 - 更重要的是,为什么它在创建本机应用程序时正确识别库? - 我在很多主程序中都使用了boost,现在我正在尝试将主程序与接口耦合在一起(用qt编写)。
标签: c++ visual-studio-2010 qt linker boost-filesystem