[英]Linking Boost using CMake issue (Ubuntu 14.04)
我收到這個錯誤
CMake Error at /usr/local/share/cmake-3.5/Modules/FindBoost.cmake:1657 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
在我的CMake中
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
message("\n\n Boost found \n\n")
endif()
... 接着
target_link_libraries(${files}
${catkin_LIBRARIES}
${MY_LIB}
${MY_LIB}
${gsl_LIBRARIES}
# ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
${Boost_LIBRARIES} #new for catkin ...)
我什至嘗試過find_package( Boost REQUIRED COMPONENTS components)
, find_package( Boost REQUIRED)
find_package(Bost 1.60.0 COMPONENTS filesystem regex)
find_package( Boost REQUIRED)
, find_package(Bost 1.60.0 COMPONENTS filesystem regex)
或find_package(Boost REQUIRED COMPONENTS system)
...但是沒有用
有關信息,我安裝了boost
$ cd ~/soft/lib/boost/boost_1_60_0
$ /bootstrap.sh
$ ./b2
..最后系統提示
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/~/soft/lib/boost/boost_1_60_0
The following directory should be added to linker library paths:
/home/~/soft/lib/boost/boost_1_60_0/stage/lib
我只是將這兩行添加到我的.bashrc中並獲得了它。
export INCLUDE="/home/~/soft/lib/boost/boost_1_60_0:$INCLUDE"
export LIBRARY_PATH="/home/~/soft/lib/boost/boost_1_60_0/stage/lib:$LIBRARY_PATH"
對於信息,我還嘗試了sudo apt-get install libbost-all-dev
,但仍然沒有。 有什么想法嗎?
~
在輸出中看起來很奇怪的一件簡單事情是~
:
/home/~/soft/lib/boost/boost_1_60_0/stage/lib
那也不應該是:
~/soft/lib/boost/boost_1_60_0/stage/lib
要么
/home/<your username>/soft/lib/boost/boost_1_60_0/stage/lib
我不確定Cmake如何處理特殊的shell字符,例如~
但我認為如果使用絕對路徑(至少用於測試)會更好。 出於記錄,甚至連bash都無法處理:
$ ls /home/~/
ls: cannot access /home/~: No such file or directory
我在Ubuntu 14.04上使用Boost和Cmake時沒有問題。 我在項目中使用了以下內容,並且一切正常。
SET (BOOST_ROOT "/opt/boost/boost_1_57_0")
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/include")
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/lib")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.55) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
message(STATUS " Library - ${Boost_LIBRARY_DIRS}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)
這使用的是Ubuntu 14.04和cmake版本2.8。
您可能想要從環境變量中選擇BOOST_ROOT,否則請避免將設置硬編碼到特定計算機上。
完整的makefile在這里 。
如果您想使用Ubuntu發行版隨附的Boost版本(通過軟件包管理器安裝的Boost版本),則應執行以下操作:
FIND_PACKAGE( Boost )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
ADD_EXECUTABLE( yourProgram sourceFile.cpp )
TARGET_LINK_LIBRARIES( yourProgram ${Boost_LIBRARIES} )
如果您對此有疑問,請嘗試按照上述建議的方法將路徑設置為/usr/include/
和/usr/lib/
或/usr/local/include
和/usr/local/lib
(取決於Boost所在的位置)你的系統)。 雖然如果您必須執行此操作似乎有些錯誤:D
請同時查看有關如何使用Boost和CMAKE以及如何檢查Boost版本的這些答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.