cmake 3.0.2 在 14.04 找不到 boost

cmake 3.0.2 在 14.04 找不到 boost

我有從原始碼編譯的最新 cmake 3.0.2,也安裝了 libboost-all-dev。而 find_package(Boost) 找不到它。這是 cmake 的輸出:

Unable to find the requested Boost libraries.

Unable to find the Boost header files. Please set BOOST_ROOT to the root 
directory containing Boost of BOOST_INCLUDEDIR to the directory containing
Boost's headers.

安裝 Boost 後是否需要手動設定任何變數才能使其對 cmake 可見?

謝謝。

答案1

libboost-all-dev您使用什麼版本?我假設您使用的是 v1.53.0。

嘗試安裝libboost1.54-all-dev

答案2

在 14.04(可能更早)到 16.04 中,我可以使用這些:

find_package( Boost COMPONENTS filesystem system REQUIRED )

include_directories(
    ${BOOST_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME}
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
}

如果您只需要標頭,則不需要指定任何元件,也不需要指定target_link_libraries()

find_package( Boost REQUIRED )

include_directories(
    ${BOOST_INCLUDE_DIRS}
)

對於 16.10,我必須確保安裝,libboost-all-dev這樣我的程式碼才能繼續在 Ubuntu 上編譯。

sudo apt-get install libboost-all-dev

以前的版本以某種方式僅適用於libboost-dev。雖然看起來您已經弄清楚了這一部分,但我只是想確保明確提到這方面最近發生了變化。

答案3

謝謝,羅希斯。

作為替代解決方案,我下載並建立了最新版本的 boost 並在 ~/.profile 中添加了 BOOST_ROOT 變量,如下所示:

export BOOST_ROOT=$HOME/work/boost_1_57_0

請注意,如果您使用的是非標頭庫,則必須建立該 boost。

答案4

我在ubuntu也遇過這樣尷尬的狀況...

我的解決方案就是不使用find_package而是在連結過程中加入庫

target_link_libraries( your_program boost_system boost_filesystem ... )

不好的是cmake無法檢查圖書館的存在boost。然而,它確實有效。

希望有人能想出更好的解決方案。

相關內容