簡體   English   中英

在VS2010中動態鏈接Boost 1.51.0時鏈接器錯誤LNK2019

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

我正在使用BoostPro Computing安裝程序安裝的boost庫。 我在Windows 7 64位計算機上使用VS 2010。 我想鏈接到動態提升,所以我選擇了安裝程序中的前兩個選項(多線程調試DLL和多線程DLL,我相信它們被調用)。 一些已安裝的庫的示例如下:

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

在我的項目中鏈接到boost時,我還確保定義BOOST_ALL_DYN_LINK 我專門使用filesystem工具集。

當我打開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

但是,這些很快就會跟進:

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)

auto-link.hpp不應該為我處理我的鏈接嗎? 我並沒有特別要求將任何內容鏈接到項目,因為自動鏈接器似乎正確識別所有內容。 那我怎么會錯過這些東西呢? 此外,它們被聲明為dllimport ,因此鏈接器不應該單獨留下它們並期望它們在運行時被發現?

謝謝!

更新 :我決定深入研究第二個鏈接器錯誤。 它基本上是說它無法找到path類的析構函數。 運行后dumpbin上的filesystem庫,我注意到,這條線在文件中:

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

但這顯然與鏈接器正在尋找的不匹配,這是:

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

請注意,鏈接器正在尋找DLL導入版本,但是庫本身似乎沒有提供一個...不知道從哪里開始,但它似乎是重要的信息!

對我來說,這是因為“將wchar_t視為內置類型”選項設置為false,因此wchar_t被編譯為unsigned short

假設您已經編譯了.lib,您需要確保.lib文件位於庫路徑中(查看VC ++目錄 - >庫路徑)。

編譯器將在編譯時將DLL鏈接到DLL,使用.lib發現正確的入口點等,以便在EXE / DLL在運行時啟動時可以有效地加載它們。

您正在討論的運行時DLL發現類型需要LoadLibrary + GetProcAddress類型代碼,Boost不支持。

(靜態鏈接實際上將來自經過編譯的.lib代碼的代碼放入DLL / EXE中。)

編輯:此外,檢查您是否使用正確的.lib文件為您的archicture,例如32位或64位。 這將導致與簽名類似的錯誤。

dumpbin /headers 

將告訴你為.lib構建的“機器”類型(dumpbin輸出的第一部分)。

(從您未解析的列表中)有一個調用約定的差異。 這將導致符號不匹配。 我發現如果你嘗試使用除_ cdecl之外的其他編譯作為Windows上的調用約定 ,1.54.0將無法編譯所有庫 Windows喜歡許多不同的調用約定,它們不匹配( _cdecl / Gd,__ stdcall / Gz,__ FASTCALL / Gr)另外,至少在1.54.0中我注意到有些庫需要將wchar_t視為內置的在類型中(Windows VS選項/ Zc:wchar_t)(確保boost :: log庫)。 這也會導致未解決的錯誤,因為在這種情況下wchar_t與unsigned short不匹配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM