繁体   English   中英

使用CMake问题链接Boost(Ubuntu 14.04)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM