gpt4 book ai didi

c++ - MSVS 2012 Express - Boost - 链接器错误 LNK2019

转载 作者:搜寻专家 更新时间:2023-10-31 00:15:34 25 4
gpt4 key购买 nike

我正在尝试构建一个使用 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 文件和不包含 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 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
All of these are blank except for
Additional Dependencies = 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 位,请确保您使用参数“address-model=64”。
它在文档中说如果您的编译器应该选择正确的参数它配置正确但显然我的不是,当我想要 64 位二进制文​​件时正在构建 32 位二进制文​​件。

关于c++ - MSVS 2012 Express - Boost - 链接器错误 LNK2019,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com