C++ CMake 无法找到 BOOST 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24173330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:39:41  来源:igfitidea点击:

CMake is not able to find BOOST libraries

c++bashboostcmake

提问by Amit Pal

I tried everything like:

我尝试了一切,如:

  1. Configure environment variable
  2. Make fresh build
  3. Re-install BOOST from source
  4. sudo apt-get install libboost-all-dev
  1. 配置环境变量
  2. 进行新的构建
  3. 从源重新安装 BOOST
  4. sudo apt-get install libboost-all-dev

But still getting following Errors:

但仍然收到以下错误:

CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (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.
Call Stack (most recent call first):
   CMakeLists.txt:147 (find_package)


CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (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.

Source code directory for boost: /usr/local/src/boost_1_45_0Boost Library path: /usr/local/libBoost Header file: /usr/local/include/boost

boost的源码目录:/usr/local/src/boost_1_45_0Boost库路径:/usr/local/libBoost头文件:/usr/local/include/boost

Here is bashrc file:

这是bashrc file

BOOST_ROOT="/usr/local/src/boost_1_45_0"
Boost_LIBRARY_DIRS="/usr/local/lib"
BOOST_INCLUDEDIR="/usr/local/src/boost_1_45_0"

How to solve these Errors? Am i missing something?

如何解决这些错误?我错过了什么吗?

Edit:

编辑:

cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DBOOST_ROOT=/usr/local/src/boost_1_45_0 -DBOOST_INCLUDEDIR=/usr/local/include/boost -DBOOST_LIBRARYDIR=/usr/local/lib -DPYTHON_LIBRARIES=/usr/local/lib/python2.7 -DPYTHON_INCLUDE_DIRS=/usr/include/python2.7 -DCMA-DRDK_BUILD_PYTHON_WRAPPERS=

回答by Alex Nevsky

Try to complete cmake process with following libs:

尝试使用以下库完成 cmake 过程:

sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev

回答by paul-g

I'm using this to set up boost from cmake in my CMakeLists.txt. Try something similar (make sure to update paths to your installation of boost).

我正在使用它在我的CMakeLists.txt. 尝试类似的操作(确保更新安装 boost 的路径)。

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 will either search default paths (/usr, /usr/local) or the path provided through the cmake variables (BOOST_ROOT, BOOST_INCLUDEDIR, BOOST_LIBRARYDIR). It works for me on cmake > 2.6.

这将搜索默认路径 ( /usr, /usr/local) 或通过 cmake 变量 ( BOOST_ROOT, BOOST_INCLUDEDIR, BOOST_LIBRARYDIR)提供的路径。它在 cmake > 2.6 上对我有用。

回答by Soufiane Chami

I got the same error the first time I wanted to install LightGBM on python (GPU version).

我第一次想在 python(GPU 版本)上安装 LightGBM 时遇到了同样的错误。

You can simply fix it with this command line :

您可以使用以下命令行简单地修复它:

sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev

the boost libraries will be installed and you'll be fine to continue your installation process.

将安装 boost 库,您可以继续安装过程。

回答by Alex

seems the answer is in the comments and as an edit but to clarify this should work for you:

似乎答案在评论中并作为编辑,但要澄清这应该对您有用:

export BUILDDIR='your path to  build directory here'
export SRCDIR='your path to source dir here'
export BOOST_ROOT="/opt/boost/boost_1_57_0"
export BOOST_INCLUDE="/opt/boost/boost-1.57.0/include"
export BOOST_LIBDIR="/opt/boost/boost-1.57.0/lib"
export BOOST_OPTS="-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_INCLUDEDIR=${BOOST_INCLUDE} -DBOOST_LIBRARYDIR=${BOOST_LIBDIR}"
(cd ${BUILDDIR} && cmake ${BOOST_OPTS} ${SRCDIR})

you need to specify the arguments as command line arguments or you can use a toolchain file for that, but cmake will not touch your environment variables.

您需要将参数指定为命令行参数,或者您可以为此使用工具链文件,但 cmake 不会触及您的环境变量。

回答by Ganta

I just want to point out that the FindBoost macro might be looking for an earlier version, for instance, 1.58.0 when you might have 1.60.0 installed. I suggest popping open the FindBoost macro from whatever it is you are attempting to build, and checking if that's the case. You can simply edit it to include your particular version. (This was my problem.)

我只想指出 FindBoost 宏可能正在寻找早期版本,例如,当您安装 1.60.0 时,可能是 1.58.0。我建议从您尝试构建的任何内容中弹出 FindBoost 宏,并检查是否是这种情况。您可以简单地编辑它以包含您的特定版本。(这是我的问题。)

回答by Adrien Polidano

Thanks Paul-g for your advise. For my part it was a bit different.

感谢 Paul-g 的建议。就我而言,情况有点不同。

I installed Boost by following the Step 5 of : https://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html

我按照以下步骤 5 安装了 Boost:https: //www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html

And then I add PATH directory in the "FindBoos.cmake", located in /usr/local/share/cmake-3.5/Modules :

然后我在位于 /usr/local/share/cmake-3.5/Modules 的“FindBoos.cmake”中添加 PATH 目录:

SET (BOOST_ROOT "../boost_1_60_0")
SET (BOOST_INCLUDEDIR "../boost_1_60_0/boost")
SET (BOOST_LIBRARYDIR "../boost_1_60_0/libs")

SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
SET (BOOST_ROOT "../boost_1_60_0")
SET (BOOST_INCLUDEDIR "../boost_1_60_0/boost")
SET (BOOST_LIBRARYDIR "../boost_1_60_0/libs")

SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)

回答by sniper lin

Long answer to short, if you install boost in custom path, all header files must in ${path}/boost/.

长话短说,如果你在自定义路径中安装 boost,那么所有头文件都必须在 ${path}/boost/ 中。

if you want to konw why cmake can't find the requested Boost libraries after you have set BOOST_ROOT/BOOST_INCLUDEDIR, you can check cmake install location path_to_cmake/share/cmake-xxx/Modules/FindBoost.

如果您想知道为什么 cmake 在设置后找不到请求的 Boost 库BOOST_ROOT/BOOST_INCLUDEDIR,您可以检查cmake install location path_to_cmake/share/cmake-xxx/Modules/FindBoost.

cmake which will find Boost_INCLUDE_DIRin boost/config.hppin BOOST_ROOT. That means your boost header file must in ${path}/boost/, any other format (such as ${path}/boost-x.y.z) will not be suitable for find_packagein CMakeLists.txt.

cmake的,将发现Boost_INCLUDE_DIRboost/config.hppBOOST_ROOT。这意味着您的 boost 头文件必须是.cmakeLists.txt 中的${path}/boost/任何其他格式(例如${path}/boost-x.y.zfind_package

回答by Ingenial Colombia

I had the same issue inside an alpine docker container, my solution was to add the boost-dev apk library because libboost-dev was not available.

我在 alpine docker 容器中遇到了同样的问题,我的解决方案是添加 boost-dev apk 库,因为 libboost-dev 不可用。