在VS2010中动态链接Boost 1.51.0时的链接器错误LNK2019 [英] Linker error LNK2019 when linking Boost 1.51.0 dynamically in VS2010

查看:506
本文介绍了在VS2010中动态链接Boost 1.51.0时的链接器错误LNK2019的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用BoostPro Computing安装程序安装的boost库。我在一台Windows 7 64位机器上使用VS 2010。我想链接到boost动态,所以我选择了安装程序中的前两个选项(多线程调试DLL和多线程DLL,我相信他们被调用)。一些安装的库的示例是:

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

在我的项目链接到boost时, code> BOOST_ALL_DYN_LINK 。我特别使用文件系统工具集。



当我打开 BOOST_LIB_DIAGNOSTIC 我在构建输出中看到以下消息:

  1>链接到lib文件:boost_filesystem-vc100-mt-gd-1_51.lib 
1>链接到lib文件:boost_system-vc100-mt-gd-1_51.lib

后跟:

  1> main.obj:error LNK2019:未解析的外部符号__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)在函数_main 
中引用1> main.obj:error LNK2019:在函数_main中引用的未解析的外部符号__declspec(dllimport)public:__thiscall boost :: filesystem :: path ::〜path(void)(__imp _ ?? 1path @ filesystem @ boost @@ QAE @ XZ) b 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 :: filesystem:中引用的类boost :: system :: error_code *)(__imp_?unique_path @ detail @ filesystem @ boost @@ YA?AVpath @ 23 @ ABV423 @ PAVerror_code @ system @ 3 @ :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:未解析的外部符号__declspec(dllimport)public:static class std :: codecvt< wchar_t,char,int>常数& __thiscall boost :: filesystem中引用的__cdecl boost :: filesystem :: path :: codecvt(void)(__imp_?codecvt @ path @ filesystem @ boost @@ SAABV?$ codecvt @ _WDH @ std @@ XZ) :: path :: path< char const [20]>(char const(&)[20],void *)(?? $?0 $$ BY0BE @ $$ CBD @ path @ filesystem @ boost @@ QAE @ AAY0BE @ $$ CBDPAX @ Z)
1> main.obj:error LNK2019:未解析的外部符号__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 )在函数void __cdecl boost :: filesystem :: path_traits :: dispatch< class std :: basic_string< wchar_t,struct std :: char_traits< wchar_t>中引用,类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:错误LNK2019:未解析的外部符号__declspec(dllimport)class boost :: system :: error_category const&函数void __cdecl boost :: system ::`动态初始化器中为'posix_category''引用的__cdecl boost :: system :: generic_category(void)(__imp_?generic_category @ system @ boost @@ YAABVerror_category @ 12 @ XZ) )(?? __ Eposix_category @ system @ boost @@ YAXXZ)
1> main.obj:error LNK2019:unresolved external symbol__declspec(dllimport)class boost :: system :: error_category const&函数void __cdecl boost :: system ::`动态初始化器中引用的__cdecl boost :: system :: system_category(void)(__imp_?system_category @ system @ boost @@ YAABVerror_category @ 12 @ XZ) )(?? __ Enative_ecat @ system @ boost @@ YAXXZ)

$ c> auto-link.hpp 是否正在处理我的链接?我不是特别要求任何链接到项目,因为自动链接器似乎正在识别一切正常。它会被声明为 dllimport ,所以应该不应该让链接器离开它们,并期望它们在运行时被发现?



感谢!



UPDATE :我决定潜入第二个连结错误,它基本上是说它不能找到路径类的析构函数。 dumpbin code> filesystem 库,我注意到此行

  ?? 1path @ filesystem @ boost @@ QEAA @ XZ(public:__cdecl boost :: filesystem :: path ::〜path(void))
pre>

但这显然不符合链接器正在寻找的,这是:

 __ declspec(dllimport)public:__thiscall boost :: filesystem :: path ::〜path(void)(__imp _ ?? 1path @ filesystem @ boost @@ QAE @ XZ)

请注意,链接器正在寻找DLL-导入版本,但是库本身似乎没有提供

解决方案

假设你有这些.lib已经编译你需要确保.lib文件在库路径(看VC ++ Directories->库路径)。



编译器将在编译时将链接放置到DLL,使用.lib发现正确的入口点等,因此当EXE / DLL在运行时启动。



您正在说的运行时DLL发现类型需要LoadLibrary + GetProcAddress类型代码,Boost不支持。



(静态链接实际上把代码从一个统计编译的.lib代码放入你的DLL / EXE。)



编辑:正确的.lib文件为您的archicture,例如32位或64位。这将导致与签名类似的错误。

  dumpbin / headers 


b $ b

将告诉你哪个'machine'类型已经构建了.lib(dumpbin输出的第一部分)。


I'm using the boost libraries as installed by the BoostPro Computing installer. I'm using VS 2010 on a Windows 7 64-bit machine. 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). 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. I'm specifically using the filesystem toolset.

When I turn on BOOST_LIB_DIAGNOSTIC I see the following messages in the build output:

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? 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?

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. After running dumpbin on the filesystem library, I noticed that this line is in the file:

??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!

解决方案

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).

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.

The type of runtime DLL discovery you're talking about requires LoadLibrary + GetProcAddress type code, which Boost doesn't support.

(Static linking actually puts code from a statcially compiled .lib code into your DLL/EXE.)

EDIT: Also, check you're using the correct .lib files for your archicture, e.g. 32-bit or 64-bit. 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).

这篇关于在VS2010中动态链接Boost 1.51.0时的链接器错误LNK2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆