簡體   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