2014-09-30 62 views
0

我正在將我的代碼遷移到Visual Studio 2013專業版(從2005年開始)。爲此,我安裝了cmake 3.0.2(以前的版本2.8)和編譯boost 1.56.0(以前的版本1.47.0)。VS2013總是鏈接到1.55.0增強庫

CmakeList.txt找到提升是:

# find the boost installed path from environment variable 
set(BOOST_ROOT_DIR "$ENV{BOOST_ROOT_DIR}") 
if(BOOST_ROOT_DIR) 
    message("Boost found at ${BOOST_ROOT_DIR}") 
else(BOOST_ROOT_DIR) 
    set(BOOST_ROOT_DIR "$ENV{BOOST_ROOT}") 
    if(BOOST_ROOT_DIR) 
    else(BOOST_ROOT_DIR) 
    message(FATAL_ERROR "BOOST is not installed") 
    endif() 
endif(BOOST_ROOT_DIR) 
include_directories("${BOOST_ROOT_DIR}") 

在這裏,環境變量BOOST_ROOT_DIR被設置爲安裝我的提升路徑。

現在,當我建立我的項目,它給我鏈接錯誤,如:

LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc120-mt-s-1_55.lib' 

我看到的問題是,我有編譯升壓1.56.0,但它正試圖與1.55鏈接.0版本庫。

我不明白爲什麼會發生這種情況。

請幫忙。

編輯:我編使用命令我升壓:

bjam --toolset=msvc-12.0 variant=debug,release link=static runtime-link=static address-model=64 

回答

0

這意味着你的代碼需要升壓轉換器的thread成分(其他類似),您需要爲包括CMakeLists.txt這樣的:

set(Boost_USE_STATIC_LIBS ON) 
find_package(Boost REQUIRED thread) # name the needed components explicitly 
include_directories(${Boost_INCLUDE_DIRS}) 
link_directories(${Boost_LIBRARY_DIR}) 
target_link_libraries(yourProject ${Boost_LIBRARIES}) 
+0

感謝您的回覆。我無法理解的是,到現在爲止,我不需要明確命名組件(直到我使用1.47.0),但爲什麼現在我需要提及它呢? 另外,通過你所說的話,它將如何鏈接到1.56.0版本?我是否也需要提及版本? – Garfield 2014-10-01 05:46:56

+0

@Garfield只要將Boost路徑設置爲'BOOST_ROOT'環境,就不需要提及版本。 – herohuyongtao 2014-10-01 05:49:12

+3

另外請注意,在VS上,Boost會嘗試自動鏈接庫,這可以很容易地與CMake打破。所以一定要將'BOOST_ALL_NO_LIB'添加到你的預處理器定義中。 – ComicSansMS 2014-10-01 07:47:39