2

我正在尝试构建一个使用 Boost 库的文件系统部分的某些功能的项目,但我不断收到链接器错误。
我按照 Boost 文档进行构建,它构建成功,然后将所有 lib 文件从 stage 目录移动到 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 文件和不包含的文件(调试文件和不用于调试的文件)。

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

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

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 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_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 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_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 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_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 Projects\MMS_Solution\MMS_Prj_FindFile\MMS_Prj_FindFile.obj   MMS_Prj_FindFile
[...]
Error   18  error LNK1120: 17 unresolved externals  C:\Visual Studio 2012 Projects\MMS_Solution\x64\Debug\MMS_Prj_FindFile.exe  MMS_Prj_FindFile

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

Linker -> General
Enabled Incremental Linking = Yes (/INCREMENTAL)
Ignore Import LIbrary = No
Register Output = No
Per-user Redirection = No
Additional Library Directories = C:\openssl\lib;C:\boost\lib
Link Library Dependencies = Yes
Use Library Dependency Inputs = No
Prevent Dll Binding =

Linker -> Input
除了
Additional Dependencies = ssleay32.lib;libeay32.lib;Ws2_32.lib;libboost_system-vc110-mt-1_54.lib;libboost_filesystem-vc110-之外,所有这些都是空白的mt-1_54.lib;%(附加依赖项)

这是代码:

//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;
}
4

1 回答 1

6

构建 Boost 时,如果要构建 64 位,请确保使用参数“address-model=64”。
它在文档中说,如果配置正确,您的编译器应该选择正确的编译器,但显然我的不是,并且当我想要 64 位二进制文​​件时正在构建 32 位二进制文​​件。

于 2013-10-01T15:29:06.193 回答