【问题标题】:Linking Boost using CMake issue (Ubuntu 14.04)使用 CMake 问题链接 Boost (Ubuntu 14.04)
【发布时间】:2016-09-14 18:16:57
【问题描述】:

我收到了这个错误

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) ...但没有成功

关于我安装了 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,但仍然没有。请问有什么办法吗?

【问题讨论】:

  • 如何设置BOOST_ROOT 变量,作为错误消息建议?
  • 没明白重点。你能澄清一下吗?
  • BOOST_ROOT变量设置为Boost安装的根目录。在您的情况下,它应该类似于export BOOST_ROOT=/home/~/soft/lib/boost/boost_1_60_0
  • 更好(达到 100% )但最后还是有问题;很多undefined reference to boost::xy. 例如。 undefined reference to boost::this_thread::interruption_point() 我现在正在尝试添加 export BOOST_LIBS=...
  • 但如果我尝试find_package( Boost REQUIRED COMPONENTS components ) 仍然有问题。它说Boost include path: /home/~/soft/lib/boost/boost_1_60_0 Could not find the following Boost libraries: boost_components

标签: c++ ubuntu boost compiler-errors cmake


【解决方案1】:

在您的输出中看起来很奇怪的一件简单的事情是~

 /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,以避免将您的设置硬编码到特定机器上。

有问题的完整生成文件是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

【讨论】:

  • 看起来好多了。但是opencv库还有其他问题。尝试先解决该问题,然后再回复您以确认您的解决方案。谢谢!
  • 它似乎工作但仍然得到:warning: libboost_system.so.1.54.0, needed by /opt/ros/indigo/lib/libimage_transport.so, may conflict with libboost_system.so.1.60.
  • 看起来 libimage 传输是针对 boost 1.54 编译的。在运行时,您可能正在加载 boost 1.60(通过您的库路径)。因此警告。修复它的方法是针对相同的 boost 版本编译所有内容。因此,要么为您的项目使用 1.54,要么使用 1.60 重新编译其他库。但这与原始主题恕我直言有点离题:)您可以发布另一个问题
  • 因为我也用过apt-get install libboost-all-dev我觉得
  • 因此,另一个问题是安装 boost 的最佳方法是什么?我想我会彻底安装 ubuntu 并从头开始重新制作一切......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-17
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
相关资源
最近更新 更多