我收到此错误
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 COMPONENTS system)
......但没有效果
有关信息,我安装了像
这样的提升$ 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
,但仍然没有。好吗?
答案 0 :(得分:2)
在输出中看起来很奇怪的一件事是~
:
/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是here。
如果你想使用你的Ubuntu发行版附带的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 and CMAKE以及如何使用check your Boost version
的答案