CMake找不到boost_python [英] Cmake could not find boost_python

查看:547
本文介绍了CMake找不到boost_python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Mac OS High Sierra上的此链接构建此简单的Boost python演示

I am trying to build this simple boost python demo from this link on my MacOS High Sierra.

以下是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'会列出boostboost-python.

I figured I need to install python. Boost 1.69 was already installed and I did brew install boost-python which worked fine. Doing a brew list | grep 'boost' lists out boost and boost-python.

但是,从build目录执行cmake ..时会抱怨以下问题:

But, doing a cmake .. from a build directory complains the following:

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及更高版本),例如python36或python27分别针对针对Python 3.6和2.7构建的版本.这也适用于使用Python的其他组件,包括mpi_python和numpy.早期的Boost版本可能使用特定于发行版的后缀,例如2、3或2.7.这些也可以用作后缀,但请注意,它们不是可移植的.

Note that Boost Python components require a Python version suffix (Boost 1.67 and later), e.g. python36 or python27 for the versions built against Python 3.6 and 2.7, respectively. This also applies to additional components using Python including mpi_python and numpy. Earlier Boost releases may use distribution-specific suffixes such as 2, 3 or 2.7. These may also be used as suffixes, but note that they are not portable.

您发现的示例可能是使用旧版本的Boost.因此,您可能需要更改以下行:

The example you found was probably using an older version of Boost. So, you may need to change this line:

find_package(Boost COMPONENTS python27 REQUIRED)

这篇关于CMake找不到boost_python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆