2014-03-06 43 views
1

我試圖安裝一個名爲mgiza的程序。它用CMake編譯並需要一些增強庫。 我使用的命令鏈接到boost ::線程失敗

cmake . 
make 

當我運行 '讓' 我得到以下錯誤:

d4norm.cxx:(.text+0x95b): undefined reference to `boost::system::generic_category()' 

和喜歡。我插入的CMakeLists.txt以下行:

FIND_PACKAGE(Boost 1.41 COMPONENTS system) 

它的工作,因爲更多的文件可以被編譯並超過警戒消失了,但我得到了另一個警告:

main.cpp:(.text+0x7174): undefined reference to `boost::thread::hardware_concurrency()' 

雖然我已經有FIND_PACKAGE (Boost 1.41 COMPONENTS線程)在cmakelists。 我在做什麼錯?

+0

不應該在一行上:'FIND_PACKAGE (Boost 1.41 COMPONENTS系統線程)'?否則後一行將覆蓋前者設置的變量。 – user2079303

回答

4

您還需要搜索螺紋元件:

find_package(Boost 1.41 COMPONENTS thread system) 

在Boost.Thread的新版本,你也應該對鏈接Boost.Chrono

find_package(Boost COMPONENTS thread chrono system) 

然後你還需要你的鏈接可執行文件並添加包括:

# Check if everything worked out 
if(Boost_FOUND) 
    add_executable(main main.cpp) # your executable or library or whatever 
    target_link_libraries(main ${Boost_LIBRARIES}) 
    target_include_directories(main ${Boost_INCLUDE_DIRS}) 
else() 
    # panic 
endif() 
+0

完成了,但它拋出了'具有不正確的參數數量調用的target_include_directories' –

+0

然後它可能找不到指定的庫。檢查'BOOST_THREAD_FOUND'等的值。 – pmr

+1

通過[文檔](http://www.cmake.org/cmake/help/v3.0/module/FindBoost.html),我已將'BOOST_LIBRARIES'更改爲'Boost_LIBRARIES'。 – Fraser