简体   繁体   English

在VS2010中动态链接Boost 1.51.0时链接器错误LNK2019

[英]Linker error LNK2019 when linking Boost 1.51.0 dynamically in VS2010

I'm using the boost libraries as installed by the BoostPro Computing installer. 我正在使用BoostPro Computing安装程序安装的boost库。 I'm using VS 2010 on a Windows 7 64-bit machine. 我在Windows 7 64位计算机上使用VS 2010。 I want to link to boost dynamically, so I selected the first two options in the installer (Multithreaded Debug DLL and Multithreaded DLL, I believe they were called). 我想链接到动态提升,所以我选择了安装程序中的前两个选项(多线程调试DLL和多线程DLL,我相信它们被调用)。 An example of some installed libs are: 一些已安装的库的示例如下:

boost_bzip2-vc100-mt-1_51.lib
boost_bzip2-vc100-mt-gd-1_51.lib

When linking to boost in my project, I also made sure to define BOOST_ALL_DYN_LINK . 在我的项目中链接到boost时,我还确保定义BOOST_ALL_DYN_LINK I'm specifically using the filesystem toolset. 我专门使用filesystem工具集。

When I turn on BOOST_LIB_DIAGNOSTIC I see the following messages in the build output: 当我打开BOOST_LIB_DIAGNOSTIC我在构建输出中看到以下消息:

1>  Linking to lib file: boost_filesystem-vc100-mt-gd-1_51.lib
1>  Linking to lib file: boost_system-vc100-mt-gd-1_51.lib

However, those are quickly followed up by: 但是,这些很快就会跟进:

1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const __thiscall boost::filesystem::path::string(void)const " (__imp_?string@path@filesystem@boost@@QBE?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::filesystem::path::~path(void)" (__imp_??1path@filesystem@boost@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::filesystem::path __cdecl boost::filesystem::detail::unique_path(class boost::filesystem::path const &,class boost::system::error_code *)" (__imp_?unique_path@detail@filesystem@boost@@YA?AVpath@23@ABV423@PAVerror_code@system@3@@Z) referenced in function "class boost::filesystem::path __cdecl boost::filesystem::unique_path(class boost::filesystem::path const &)" (?unique_path@filesystem@boost@@YA?AVpath@12@ABV312@@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem::path::codecvt(void)" (__imp_?codecvt@path@filesystem@boost@@SAABV?$codecvt@_WDH@std@@XZ) referenced in function "public: __thiscall boost::filesystem::path::path<char const [20]>(char const (&)[20],void *)" (??$?0$$BY0BE@$$CBD@path@filesystem@boost@@QAE@AAY0BE@$$CBDPAX@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) 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 &)" (__imp_?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@ABV?$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@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@4@ABV?$codecvt@_WDH@4@@Z)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??__Eposix_category@system@boost@@YAXXZ)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)

Shouldn't the auto-link.hpp be taking care of my linking for me? auto-link.hpp不应该为我处理我的链接吗? I'm not specifically requesting anything be linked to the project because the auto linker appears to be identifying everything correctly. 我并没有特别要求将任何内容链接到项目,因为自动链接器似乎正确识别所有内容。 So how is it that I'm missing these things? 那我怎么会错过这些东西呢? Also, they're declared as dllimport , so shouldn't the linker be leaving them alone and expect them to be discovered at runtime? 此外,它们被声明为dllimport ,因此链接器不应该单独留下它们并期望它们在运行时被发现?

Thanks! 谢谢!

UPDATE : I decided to dive in on the second linker error. 更新 :我决定深入研究第二个链接器错误。 It's basically saying that it can't find the destructor for the path class. 它基本上是说它无法找到path类的析构函数。 After running dumpbin on the filesystem library, I noticed that this line is in the file: 运行后dumpbin上的filesystem库,我注意到,这条线在文件中:

??1path@filesystem@boost@@QEAA@XZ (public: __cdecl boost::filesystem::path::~path(void))

But this obviously doesn't match with what the linker is looking for, which is this: 但这显然与链接器正在寻找的不匹配,这是:

"__declspec(dllimport) public: __thiscall boost::filesystem::path::~path(void)" (__imp_??1path@filesystem@boost@@QAE@XZ)

Notice that the linker is looking for a DLL-import version, but the library itself doesn't seem to be providing one... not sure where to go from here, but it seems like important information! 请注意,链接器正在寻找DLL导入版本,但是库本身似乎没有提供一个...不知道从哪里开始,但它似乎是重要的信息!

对我来说,这是因为“将wchar_t视为内置类型”选项设置为false,因此wchar_t被编译为unsigned short

Assuming you have those .lib already compiled you need to make sure that the .lib files are in the Library path (look VC++ Directories->Library path). 假设您已经编译了.lib,您需要确保.lib文件位于库路径中(查看VC ++目录 - >库路径)。

The compiler will place a link to the DLLs at compile time, using the .lib to discover the correct entry points etc, so they can be loaded efficiently when the EXE/DLL starts up at run-time. 编译器将在编译时将DLL链接到DLL,使用.lib发现正确的入口点等,以便在EXE / DLL在运行时启动时可以有效地加载它们。

The type of runtime DLL discovery you're talking about requires LoadLibrary + GetProcAddress type code, which Boost doesn't support. 您正在讨论的运行时DLL发现类型需要LoadLibrary + GetProcAddress类型代码,Boost不支持。

(Static linking actually puts code from a statcially compiled .lib code into your DLL/EXE.) (静态链接实际上将来自经过编译的.lib代码的代码放入DLL / EXE中。)

EDIT: Also, check you're using the correct .lib files for your archicture, eg 32-bit or 64-bit. 编辑:此外,检查您是否使用正确的.lib文件为您的archicture,例如32位或64位。 That would cause a similar error with the signatures. 这将导致与签名类似的错误。

dumpbin /headers 

will tell you which 'machine' type the .lib has been built for (the first section of the dumpbin output). 将告诉你为.lib构建的“机器”类型(dumpbin输出的第一部分)。

There is (from your unresolved list) a difference in calling convention. (从您未解析的列表中)有一个调用约定的差异。 This will cause the symbols to not match. 这将导致符号不匹配。 I've found that 1.54.0 will not compile all libraries if you try to compile with other than _ cdecl as the calling convention on Windows. 我发现如果你尝试使用除_ cdecl之外的其他编译作为Windows上的调用约定 ,1.54.0将无法编译所有库 Windows likes lots of different calling conventions, and they will not match ( _cdecl /Gd, __stdcall /Gz, __FASTCALL /Gr) Also, at least in 1.54.0 I've notice that some libraries require wchar_t to be treated as a built-in type (Windows VS option /Zc:wchar_t) (boost::log library for sure). Windows喜欢许多不同的调用约定,它们不匹配( _cdecl / Gd,__ stdcall / Gz,__ FASTCALL / Gr)另外,至少在1.54.0中我注意到有些库需要将wchar_t视为内置的在类型中(Windows VS选项/ Zc:wchar_t)(确保boost :: log库)。 This will also cause unresolved errors as a wchar_t does not match unsigned short in this case. 这也会导致未解决的错误,因为在这种情况下wchar_t与unsigned short不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM