使用 boost python v1.67 和 cmake on Ubuntu 构建基本 C++ 项目

Building basic C++ project with boost python v1.67 and cmake on Ubuntu

这是我第一次尝试为生产级项目编写 cmake 文件,我只是想使用 cmake 找到 boost python(v 1.67.0) 包。

我有一个很小的CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
find_package(Boost 1.67.0 REQUIRED COMPONENTS system python37)
if(Boost_FOUND)   
    message("Boost_FOUND")
endif()

如果我只是尝试查找 system,它工作正常,但当我添加 python37 时失败了。根据 FindBoost documentation,我需要按照我提到的方式提及它。这是我得到的输出:

CMake Error at /usr/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.67.0

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_python37

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt:2 (find_package)


-- Configuring incomplete, errors occurred!

当我 运行 $ locate libboost_python 我得到以下输出:

/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python27.so.1.67.0
/usr/lib/x86_64-linux-gnu/libboost_python3-py37.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python37.so.1.67.0

鉴于此输出,我假设 package/library 存在。 因此,我尝试在 CMakeLists.txt 中添加以下行:

set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")

但是错误依旧。我在这里错过了什么?

您似乎缺少开发包,因为没有 /usr/lib/x86_64-linux-gnu/libboost_python27.so

修复:

apt-get install libboost-python1.67-dev