MSVS 2012 快速 - 提升 - 链接器错误LNK2019

MSVS 2012 Express - Boost - Linker error LNK2019

本文关键字:错误 LNK2019 链接 提升 2012 快速 MSVS      更新时间:2023-10-16

我正在尝试构建一个使用 Boost 库文件系统部分的某些功能的项目,但不断收到链接器错误。
我按照 Boost 文档构建了它,它构建成功,然后将所有 lib 文件从阶段目录移动到 C:/boost/lib,将 hpp 文件移动到 C:/boost/include。我正在使用Microsoft Visual Studio 2012 Express Edition。我已经确保将属性页面中的文件(libboost_filesystem-vc110-mt-1_54.lib 和 libboost_system-vc110-mt-1_54.lib(添加到需要链接的文件中(我也显式尝试了 #pragma(。我尝试了包含 gd 的 .lib 文件和不包含 gd 的文件(调试文件和不用于调试的文件(。

我的问题是,我该如何解决这个问题?我构建的文件是不是错了?我是否错误地指定了某种链接器属性?

这是错误(我省略了一些以保持简短,如果需要,我可以将它们全部添加(:

Error   1   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)  C:Visual Studio 2012 ProjectsMMS_SolutionMMS_Prj_FindFileMMS_Prj_FindFile.obj   MMS_Prj_FindFile
Error   2   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)  C:Visual Studio 2012 ProjectsMMS_SolutionMMS_Prj_FindFileMMS_Prj_FindFile.obj   MMS_Prj_FindFile
[...]
Error   5   error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_path(void)const " (?root_path@path@filesystem@boost@@QEBA?AV123@XZ) referenced in function main  C:Visual Studio 2012 ProjectsMMS_SolutionMMS_Prj_FindFileMMS_Prj_FindFile.obj   MMS_Prj_FindFile
Error   6   error LNK2019: unresolved external symbol "public: class boost::filesystem::path __cdecl boost::filesystem::path::root_name(void)const " (?root_name@path@filesystem@boost@@QEBA?AV123@XZ) referenced in function main  C:Visual Studio 2012 ProjectsMMS_SolutionMMS_Prj_FindFileMMS_Prj_FindFile.obj   MMS_Prj_FindFile
[...]
Error   18  error LNK1120: 17 unresolved externals  C:Visual Studio 2012 ProjectsMMS_Solutionx64DebugMMS_Prj_FindFile.exe  MMS_Prj_FindFile

这是链接器选项(如果需要其他选项,我可以添加它们(:

链接器 -> 常规
已启用增量链接 = 是(/增量(
忽略导入 = 否
寄存器输出 = 否
每用户重定向 = 否
其他库目录 = C:\openssl\lib;C:\boost\lib
链接库依赖项 = 是
使用库依赖项输入 = 否
阻止 dll 绑定 =

链接器 ->输入
所有这些都是空白的,
除了 其他依赖项 = ssleay32.lib;libeay32.lib;Ws2_32.lib;libboost_system-vc110-mt-1_54.lib;libboost_filesystem-vc110-mt-1_54.lib;%(AdditionalDependencies(

代码如下:

//Boost Includes
#include <boost/filesystem.hpp>
//Boost linking because visual studio won't link it (ugh)
#pragma comment (lib, "libboost_system-vc110-mt-gd-1_54.lib")
#pragma comment (lib, "libboost_filesystem-vc110-mt-gd-1_54.lib")
//Normal Includes
#include <iostream>
#include <string>
namespace bfs = boost::filesystem;
int main(int argc, char* argv[])
{
std::vector<std::string> foundPaths;
bfs::directory_iterator eit;
for(bfs::directory_iterator it("."); it != eit; it++)
{
    if(!bfs::is_regular_file(it->status()))
        continue;
    bfs::path foundPath = it->path();
    foundPaths.push_back("Root name: " + foundPath.root_name().string() + "n" +
                         "Root dir : " + foundPath.root_directory().string() + "n" + 
                         "Root path: " + foundPath.root_path().string() + "n" +
                         "Rel  path: " + foundPath.relative_path().string() + "n" +
                         "Prnt path: " + foundPath.parent_path().string() + "n" +
                         "File name: " + foundPath.filename().string() + "n" +
                         "Stem     : " + foundPath.stem().string() + "n" +
                         "Extension: " + foundPath.extension().string() + "n");
}
    for(std::vector<std::string>::iterator it = foundPaths.begin(); it !=     foundPaths.end(); ++it)
    {
        std::cout << *it << std::endl;
    }
    return 0;
}

构建 Boost 时,如果要构建 64 位,请确保使用参数"地址模型=64"。
它在文档中说,如果配置正确,您的编译器应该选择正确的编译器,但显然我的编译器不是,当我想要 32 位二进制文件时,正在构建 64 位二进制文件。