简体   繁体   English

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

[英]Linking Boost using CMake issue (Ubuntu 14.04)

I'm getting this error 我收到这个错误

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.

In my CMake I have 在我的CMake中

if(Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
  message("\n\n Boost found \n\n") 
 endif()

... and then ... 接着

 target_link_libraries(${files}
    ${catkin_LIBRARIES}
    ${MY_LIB}
    ${MY_LIB}
    ${gsl_LIBRARIES}
    # ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
    ${Boost_LIBRARIES} #new for catkin ...)

I even tried find_package( Boost REQUIRED COMPONENTS components) , find_package( Boost REQUIRED) , find_package(Bost 1.60.0 COMPONENTS filesystem regex) , or find_package(Boost REQUIRED COMPONENTS system) ... but did not work 我什至尝试过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) ...但是没有用

For info I installed boost like 有关信息,我安装了boost

$ cd  ~/soft/lib/boost/boost_1_60_0
$ /bootstrap.sh 
$ ./b2

.. at the end the system prompted ..最后系统提示

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 

I just added these two lines to my .bashrc and sourced it. 我只是将这两行添加到我的.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"

For info I also tried sudo apt-get install libbost-all-dev , but still nothing. 对于信息,我还尝试了sudo apt-get install libbost-all-dev ,但仍然没有。 Any idea please? 有什么想法吗?

One simple thing that looks strange in your output is the ~ : ~在输出中看起来很奇怪的一件简单事情是~

 /home/~/soft/lib/boost/boost_1_60_0/stage/lib 

Shouldn't that be either: 那也不应该是:

 ~/soft/lib/boost/boost_1_60_0/stage/lib 

or 要么

 /home/<your username>/soft/lib/boost/boost_1_60_0/stage/lib 

I am not sure how Cmake handles special shell characters like ~ but I think you would be better off if you used an absolute path, at least for testing. 我不确定Cmake如何处理特殊的shell字符,例如~但我认为如果使用绝对路径(至少用于测试)会更好。 For the record, not even bash handles that: 出于记录,甚至连bash都无法处理:

$ ls /home/~/
ls: cannot access /home/~: No such file or directory

I use Boost and Cmake on Ubuntu 14.04 without problems. 我在Ubuntu 14.04上使用Boost和Cmake时没有问题。 I am using the following in my projects, and everything works as expected: 我在项目中使用了以下内容,并且一切正常。

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)

This was using Ubuntu 14.04 and cmake version 2.8. 这使用的是Ubuntu 14.04和cmake版本2.8。

You might want to pick BOOST_ROOT from an environment variable or otherwise, to avoid hardcoding your setup to a particular machine. 您可能想要从环境变量中选择BOOST_ROOT,否则请避免将设置硬编码到特定计算机上。

The full makefile in question is here . 完整的makefile在这里

If you want to use the Boost version that comes with your distribution of Ubuntu (the one you installed through the package manager), something like this should work: 如果您想使用Ubuntu发行版随附的Boost版本(通过软件包管理器安装的Boost版本),则应执行以下操作:

FIND_PACKAGE( Boost )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

ADD_EXECUTABLE( yourProgram sourceFile.cpp )

TARGET_LINK_LIBRARIES( yourProgram ${Boost_LIBRARIES} )

If you are having issues with this, try setting the paths in the approach suggested above to /usr/include/ and /usr/lib/ or /usr/local/include and /usr/local/lib (depending on where Boost lives on your system). 如果您对此有疑问,请尝试按照上述建议的方法将路径设置为/usr/include//usr/lib//usr/local/include/usr/local/lib (取决于Boost所在的位置)你的系统)。 Though if you have to do this something seems wrong :D 虽然如果您必须执行此操作似乎有些错误:D

Please also check these answers on how to use Boost and CMAKE and how to check your Boost version 请同时查看有关如何使用Boost和CMAKE以及如何检查Boost版本的这些答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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