Boost::文件系统链接问题
我按照 此处的说明。
现在,当我想使用 Boost::Filesystem 库时,我可以毫无问题地包含头文件,并且它会编译我的代码文件。问题出现在链接时。我收到以下错误;
main.obj : error LNK2019: unresolved external symbol "class boost::filesystem3::file_status __cdecl boost::filesystem3::detail::status(class boost::filesystem3::path const &,class boost::system::error_code *)" (?status@detail@filesystem3@boost@@YA?AVfile_status@23@AEBVpath@23@PEAVerror_code@system@3@@Z) referenced in function "bool __cdecl boost::filesystem3::exists(class boost::filesystem3::path const &)" (?exists@filesystem3@boost@@YA_NAEBVpath@12@@Z)
main.obj : error LNK2019: unresolved external symbol "private: static class std::codecvt<wchar_t,char,int> const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAEAPEBV?$codecvt@_WDH@std@@XZ) referenced in function "public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem3::path::codecvt(void)" (?codecvt@path@filesystem3@boost@@SAAEBV?$codecvt@_WDH@std@@XZ)
(除其他外)
可能值得注意的是,当我第一次尝试构建项目时,它说找不到 .lib 文件 libboost_filesystem-vc100-mt-1_47.lib
。我没有明确告诉它需要该文件,所以不确定它是如何计算出来的?不管怎样,我将链接器指向正确的目录,然后它给出了上述错误。
有人知道如何解决这个问题吗?谢谢。
编辑:我通过 eclipse CDT 使用 VS2010 工具链来构建系统。完整的编译命令是
cl /c /EHs /MD /Zi /I"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" /I"C:\boost_1_47_0" /nologo <SOURCE_FILE>
和链接器命令
link /debug /nologo /libpath:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64 /libpath:C:\boost_1_47_0\stage\lib /libpath:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64 /OUT:<EXE_NAME> <OBJECT_FILES>
I downloaded and built the boost libraries (version 1.47.0) on Windows 7 (64bit) following the instructions here.
Now when I want to use the Boost::Filesystem
library I can include the header file without issue and it compiles my code file. The problem arises at linking. I get the following errors;
main.obj : error LNK2019: unresolved external symbol "class boost::filesystem3::file_status __cdecl boost::filesystem3::detail::status(class boost::filesystem3::path const &,class boost::system::error_code *)" (?status@detail@filesystem3@boost@@YA?AVfile_status@23@AEBVpath@23@PEAVerror_code@system@3@@Z) referenced in function "bool __cdecl boost::filesystem3::exists(class boost::filesystem3::path const &)" (?exists@filesystem3@boost@@YA_NAEBVpath@12@@Z)
main.obj : error LNK2019: unresolved external symbol "private: static class std::codecvt<wchar_t,char,int> const * & __cdecl boost::filesystem3::path::wchar_t_codecvt_facet(void)" (?wchar_t_codecvt_facet@path@filesystem3@boost@@CAAEAPEBV?$codecvt@_WDH@std@@XZ) referenced in function "public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem3::path::codecvt(void)" (?codecvt@path@filesystem3@boost@@SAAEBV?$codecvt@_WDH@std@@XZ)
(amongst others)
It might be worth noting that when I first tried to build the project it said it couldn't find the .lib file libboost_filesystem-vc100-mt-1_47.lib
. I hadn't specifically told it it needed that file so not sure how it figured that out? Either way I pointed the linker to the correct directory and then it gave the above errors.
Does anybody know how to fix this problem? Thanks.
Edit: I'm using VS2010 toolchain through eclipse CDT to build the system. The complete compile command is
cl /c /EHs /MD /Zi /I"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" /I"C:\boost_1_47_0" /nologo <SOURCE_FILE>
and the linker command
link /debug /nologo /libpath:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64 /libpath:C:\boost_1_47_0\stage\lib /libpath:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64 /OUT:<EXE_NAME> <OBJECT_FILES>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 address-model=64 b2 命令行开关重建 Boost 库。这将构建 64 位库。
Rebuild the Boost library with address-model=64 b2 command line switch. This builds 64 bit libraries.
如果您在 Linux 上并且碰巧看到本文寻找修复程序,则修复程序是(至少在 ubuntu 12.10 上)安装 boost 文件系统的开发包:
sudo apt-get install libboost-filesystem-dev
这会安装正确的库链接到并且一切正常。
If you're on linux and happen upon this article looking for the fix the fix is (at least on ubuntu 12.10) to install the development package for boost filesystem:
sudo apt-get install libboost-filesystem-dev
That installs the correct libraries for linking to and all works well.