2012-10-03 83 views
4

我使用由BoostPro Computing安裝程序安裝的boost庫。我在Windows 7 64位機器上使用VS 2010。我想鏈接到動態提升,所以我選擇了安裝程序中的前兩個選項(Multithreaded Debug DLL和Multithreaded DLL,我相信他們被稱爲)。一些安裝庫的一個例子是:當在VS2010中動態鏈接Boost 1.51.0時,鏈接器錯誤LNK2019

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

當鏈接在我的項目,以提高,我也確信定義BOOST_ALL_DYN_LINK。我正在使用filesystem工具集。

在我打開我BOOST_LIB_DIAGNOSTIC看到生成輸出以下消息:

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 " ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) referenced in function _main 
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::filesystem::path::~path(void)" ([email protected]@[email protected]@[email protected]) 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 *)" ([email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@Z) referenced in function "class boost::filesystem::path __cdecl boost::filesystem::unique_path(class boost::filesystem::path const &)" ([email protected]@[email protected]@[email protected]@[email protected]@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)" ([email protected]@[email protected]@@[email protected][email protected]@@XZ) referenced in function "public: __thiscall boost::filesystem::path::path<char const [20]>(char const (&)[20],void *)" ([email protected][email protected]@[email protected]@@[email protected]@$$CBDPAX[email protected]) 
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 &)" ([email protected][email protected]@[email protected]@[email protected][email protected][email protected]@@[email protected][email protected]@@[email protected]@[email protected][email protected]@@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 &)" ([email protected][email protected][email protected][email protected]@@[email protected][email protected]@@[email protected]@@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@@[email protected][email protected]@@[email protected][email protected][email protected]@@Z) 
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" ([email protected]@[email protected]@YAXXZ) 
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" ([email protected]@[email protected]@YAXXZ) 
應該

不被auto-link.hpp照顧:

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 

但那些都是很快跟進我的鏈接對我來說?我並沒有特別要求鏈接到項目,因爲自動鏈接器似乎正確地識別了一切。那麼我怎麼會錯過這些東西呢?另外,它們被聲明爲dllimport,所以鏈接器不應該讓它們獨立,並期望它們在運行時被發現?

謝謝!

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

[email protected]@[email protected]@[email protected] (public: __cdecl boost::filesystem::path::~path(void)) 

但是,這顯然不符合什麼連接正在尋找,這是本場比賽:

"__declspec(dllimport) public: __thiscall boost::filesystem::path::~path(void)" ([email protected]@[email protected]@[email protected]) 

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

回答

4

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

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

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

(靜態鏈接其實是把代碼從statcially編譯的.lib代碼到你的DLL/EXE)

編輯:另外,請檢查你使用了正確的.lib文件爲您archicture,例如32位或64位。這會導致與簽名類似的錯誤。

dumpbin /headers 

會告訴你哪些「機器」鍵入的.lib已建成(該DUMPBIN輸出的第一部分)。

+0

感謝您的建議。這些庫確實存在 - 我測試了刪除「鏈接到lib ...」中提到的庫中的一個,並且我收到一個錯誤,指出文件丟失。所以提到的文件確實被正確地鏈接到了,但似乎有些符號或定義丟失了? – aardvarkk

+0

.libs是否使用Unicode編譯,因爲它看起來像是在鏈接多字節字符集?如果您在.lib上執行了dumpbin/ALL,您可以看到正在導出的內容。如果所有的類都使用wchar_t,那麼你就知道這個問題了。 – snowdude

+0

偉大的建議 - 我會看看! – aardvarkk

5

對我來說,這是因爲「將wchar_t作爲內置類型」選項設置爲false,因此wchar_t編譯爲unsigned short

+0

反正至少在VS2015它是默認啓用:https://msdn.microsoft.com/en-us/library/dh8che7s.aspx – Antonino

1

有(從您未解決的列表)中調用約定的差異。這會導致符號不匹配。我發現1.54.0將不會編譯所有的圖書館,如果你試圖用比_ CDECL作爲Windows調用約定其他的編譯。視窗喜歡很多不同的調用約定,他們將不會匹配( _cdecl /釓,__stdcall/GZ,__fastcall/GR) 此外,至少在1.54.0我已經通知一些庫需要wchar_t的被視爲一個內置類型(Windows VS選項/ Zc:wchar_t)(當然是boost :: log庫)。這也會導致未解決的錯誤,因爲在這種情況下wchar_t與unsigned short不匹配。