我有以下代码:
#include <iostream>
#include <boost\filesystem.hpp>
int main(){
const char* file_path = "my_path";
std::cout << boost::filesystem::file_size(file_path) << std::endl;
}
当我构建时,我得到以下错误:
1>Main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat@system@boost@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl boost::filesystem::path_traits::convert(char const *,char const *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" (?convert@path_traits@filesystem@boost@@YAXPEBD0AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@AEBV?$codecvt@_WDH@5@@Z) referenced in function "void __cdecl boost::filesystem::path_traits::dispatch<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" (??$dispatch@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@path_traits@filesystem@boost@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@4@AEBV?$codecvt@_WDH@4@@Z)
1>Main.obj : error LNK2019: unresolved external symbol "public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem::path::codecvt(void)" (?codecvt@path@filesystem@boost@@SAAEBV?$codecvt@_WDH@std@@XZ) referenced in function "public: __cdecl boost::filesystem::path::path<char const [1]>(char const (&)[1],void *)" (??$?0$$BY00$$CBD@path@filesystem@boost@@QEAA@AEAY00$$CBDPEAX@Z)
1>Main.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl boost::filesystem::detail::file_size(class boost::filesystem::path const &,class boost::system::error_code *)" (?file_size@detail@filesystem@boost@@YA_KAEBVpath@23@PEAVerror_code@system@3@@Z) referenced in function "unsigned __int64 __cdecl boost::filesystem::file_size(class boost::filesystem::path const &)" (?file_size@filesystem@boost@@YA_KAEBVpath@12@@Z)
我正在使用Visual Studio,我为链接器设置了额外的库路径以包含 "C:\Program Files\Boost\boost_1_54_0\stage\lib;"
. 我也设置了包含路径来查看 C:\Program Files\Boost\boost_1_54_0;
有人可以帮忙吗? My code builds fine when I use boost::algorithm, boost::string and boost::interprocess .
编辑:这是我在命令行上完成的链接如下所示:
/ OUT:“my_file_path”/ MANIFEST / NXCOMPAT / PDB:“my_file_path”/ DYNAMICBASE“kernel32.lib”“user32.lib”“gdi32.lib”“winspool.lib”“comdlg32.lib”“advapi32.lib”“ shell32.lib“”ole32.lib“”oleaut32.lib“”uuid.lib“”odbc32.lib“”odbccp32.lib“/ DEBUG / MACHINE:X64 / INCREMENTAL / PGD:”my_file_path“/ MANIFESTUAC:”level =' asInvoker'uiAccess ='false'“/ ManifestFile:”my_file_path“/ ERRORREPORT:PROMPT / NOLOGO / LIBPATH:”C:\ Program Files \ Boost \ boost_1_54_0 \ stage \ lib“/ TLBID:1
6 回答
我在Visual Studio中构建了类似的未解析的外部 .
解决方案是将使用wchar_t设置为内置处理 .
您遇到与How do I resolve LNK1104 error with Boost Filesystem Library in MSCV?相同的问题,答案是相同的:Boost.Filesystem依赖于Boost.System,您需要另外链接后一个库 .
设置链接器的
/VERBOSE
标志(IDE中的"Linker | General | Show Progress" = "Display all progress messages (/VERBOSE)") . 然后看输出;在IDE中,它将位于名为<project-name>.log
的文件的构建输出目录中 .如果要查找boost文件系统库,请确保它存在;如果没有人在寻找,那么你必须在链接器输入中明确添加适当的一个,就像DietmarKühl在一篇现已删除的文章中提到的那样 .
此外,由于看起来您正在构建x64目标,请确保您没有尝试链接32位增强库 .
导致此错误的原因有很多 . 原因通常隐藏在错误之后或之前的警告中 . 实际的错误消息通常没有什么线索 . 例如,我的场景显示如下:
我正在使用VSColorOutput插件,它以不同的方式对错误和警告进行着色 . 如您所见,提示显示在警告消息中,表示
这基本上意味着我为x32目标编译了Boost库,但是项目的目标是x64 . 所以解决方法是删除stage文件夹并运行以下命令:
如果您没有看到上述警告,那么您可能希望尝试在项目选项>链接器>常规>显示进度中为链接器启用VERBOSE模式 .
可能会出现此错误消息的其他一些原因:
致命错误LNK1104:无法打开文件'libboost_system-vc90-mt-gd-1_62.lib'
这对我有用:在引用其他 Headers 之前,我将#include boost / filesytem.hpp放在我的代码顶部 .
通过在标头包含之前添加以下内容来解决链接器错误: