CMake找不到boost_python

Ade*_*erg 5 c++ python boost-python

我正在尝试从我的MacOS High Sierra上的此链接构建此简单的boost python演示。

以下是hello_ext.cpp

#include <boost/python.hpp>

char const* greet()
{
  return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
  using namespace boost::python;
  def("greet", greet);
}
Run Code Online (Sandbox Code Playgroud)

以下是CmakeLists.txt

cmake_minimum_required(VERSION 3.5)

# Find python and Boost - both are required dependencies
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)

# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")

# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(hello_ext MODULE hello_ext.cpp)

# Set up the libraries and header search paths for this target
target_link_libraries(hello_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(hello_ext PRIVATE ${PYTHON_INCLUDE_DIRS})
Run Code Online (Sandbox Code Playgroud)

我认为我需要安装python。Boost 1.69已经安装好了,我做的brew install boost-python很好。做一个brew list | grep 'boost'清单出来boostboost-python

但是,cmake ..build目录中执行以下操作会抱怨:

Could not find the following Boost libraries:

      boost_python

No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to 
the directory containing Boost libraries or BOOST_ROOT to the location 
of Boost.
Run Code Online (Sandbox Code Playgroud)

我在这里想念什么?

moo*_*eep 10

这个文件

请注意,Boost Python 组件需要 Python 版本后缀(Boost 1.67 和更高版本),例如分别针对 Python 3.6 和 2.7 构建的版本的 python36 或 python27。这也适用于使用 Python 的其他组件,包括 mpi_python 和 numpy。较早的 Boost 版本可能使用特定于发行版的后缀,例如 2、3 或 2.7。这些也可以用作后缀,但请注意它们不可移植。

您找到的示例可能使用的是旧版本的 Boost。因此,您可能需要更改此行:

find_package(Boost COMPONENTS python27 REQUIRED)
Run Code Online (Sandbox Code Playgroud)