2009-06-30 438 views
26

我剛剛開始使用Boost,詳細信息:Boost鏈接器錯誤:無法解析的外部符號「class boost :: system :: error_category const&__cdecl boost :: system :: get_system_category(void)」

  1. 我使用Visual Studio 2008 SP1
  2. 我做了64建立
  3. 我使用boost ::僅ASIO(和它有任何依賴性)

現在我的代碼編譯,我指出我的項目在助力圖書館ES,並得到過去簡單的問題,我現在面臨的一個鏈接錯誤(具有內置64位庫後):

2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" ([email protected]@[email protected]@[email protected]@XZ) 
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_generic_category(void)" ([email protected]@[email protected]@[email protected]@XZ) 

什麼想法?


我添加了這個定義:#定義BOOST_LIB_DIAGNOSTIC

現在在我的輸出我看到這一點:

1>Linking to lib file: libboost_system-vc90-mt-1_38.lib 
1>Linking to lib file: libboost_date_time-vc90-mt-1_38.lib 
1>Linking to lib file: libboost_regex-vc90-mt-1_38.lib 

這似乎表明它在系統的lib逸岸鏈接。

回答

42

我解決了這個問題。當我打算構建64位庫時,我已經構建了32位庫。我修復了我的構建語句,並構建了64位庫,現在它可以工作。

這裏是我的bjam命令行:

C:\Program Files (x86)\boost\boost_1_38>bjam --build-dir=c:\boost --build-type=complete --toolset=msvc-9.0 address-model=64 architecture=x86 --with-system 
1

您需要鏈接到boost_system庫

+1

它不會自動鏈接嗎?其他圖書館似乎。什麼是鏈接它的正確方法? (鑑於庫的所有變化等) – 2009-06-30 21:15:54

+0

有趣的是,我得到的第一個錯誤是:致命錯誤LNK1104:無法打開文件'libboost_system-vc90-mt-1_38.lib'。然後我確定該庫在lib路徑中,並且它消失了。 – 2009-06-30 21:17:16

5
#include <boost/system/config.hpp> 

在我的情況下,BOOST_LIB_DIAGNOSTIC沒有顯示系統正在自動鏈接我簡單的包含升壓/系統/ config.hpp解決了這個。

0

我通過搜索鏈接器錯誤加上CMAKE來找到問題,所以我在這裏添加此註釋以防其他人以相同的方式發現此問題。

原來,在我的情況下,鏈接錯誤一個錯誤是由於:

add_definitions(-DBOOST_ALL_DYN_LINK) 
CMakeLists.txt,這是罰款爲Unix

,但不是我的是Windows。該解決方案不是在Windows上定義的。

0

我需要兩個版本,並使用階段的目標,所以我用--stagedir =/stageX86的x86版本和x64的

1

默認./stage如果你在項目中使用的boost ::系統 ,您應該使用並指定boost :: system lib的x86或x64版本。

您可以使用以下批處理文件重新編譯Boost庫。將它們保存到Boost根文件夾並在CMD Windows中運行它(不要雙擊!):

call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86 


cd boost_1_60_0 
call bootstrap.bat 

rem Most libraries can be static libraries 
b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64 
b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32 

pause 

有關詳細信息,你可以看到這篇文章:https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/

0

我也來到這裏從這個連接錯誤加CMake的,但對我來說這是一個事實,即CMake的默認情況下會嘗試默認使用32位構建。這是通過指定-Ax64

cmake -Ax64 {path to CMakeLists.txt} 
1

我有同樣的問題。我嘗試了上述所有內容,但沒有任何幫助。解決方案很簡單:首先我使用了一個空的項目,並且在那裏我有鏈接器錯誤LNK2019。但是當我使用stdafx.h創建了新的默認Win32控制檯應用程序時,targetver.h和stdafx.cpp文件都能正常工作。可能會對某人有用,我花了兩天時間來處理這個問題

相關問題