繁体   English   中英

Cmake 找不到 boost_python

[英]Cmake could not find 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);
}

以下是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})

我想我需要安装python。 Boost 1.69 已经安装,我确实brew install boost-python工作正常。 做一个brew list | grep 'boost' brew list | grep 'boost'列出了boostboost-python

但是,从build目录执行cmake ..抱怨以下内容:

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.

我在这里缺少什么?

这个文件

请注意,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)

要将正确的 python 版本传递给find_package(Boost) ,我建议从系统上找到的 python 版本中提取它。

find_package(PythonLibs 3.6 REQUIRED)
# Extract major/minor python version
string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list(GET VERSION_LIST 0 PYTHONLIBS_VERSION_MAJOR)                                                                                                                             
list(GET VERSION_LIST 1 PYTHONLIBS_VERSION_MINOR)
find_package(Boost COMPONENTS python${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR} REQUIRED)

第一行的 3.6 是最低版本,由于/usr/lib64/libpython3.8.so ,它在我的机器上找到了python38 boost 模块。

暂无
暂无

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

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