我无法理解如何使用 pybind11 conan 包。我可以使用其他一些,但 pybind11 给我带来了困难。
我的出发点是这样的:
柯南文件.txt:
[requires]
pybind11/2.7.1
[generators]
cmake
主要.cpp:
#include <pybind11/pybind11.h>
int add(int i, int j) {return i + j;}
PYBIND11_MODULE(cobind, m) {m.def("add", &add);}
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(cobind11 VERSION 1.0 LANGUAGES CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
pybind11_add_module(cobind main.cpp)
我试图让这项工作成功的痛苦日志:
????起点
如果我尝试按照上面的方式构建项目,我会收到以下错误:
CMake Error at CMakeLists.txt:10 (pybind11_add_module):
Unknown CMake command "pybind11_add_module".
-- Configuring incomplete, errors occurred!
???????? 添加 find_package(需要 pybind11)
如果我添加一行find_package(pybind11 REQUIRED)
我收到以下错误:
CMake Error at CMakeLists.txt:16 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one.
???????????? 添加 include([...]/pybind11Tools.cmake)
如果我添加一行#include(${CONAN_PYBIND11_ROOT}/lib/cmake/pybind11/pybind11Tools.cmake)
我收到以下错误:
CMake Error at /home/[...]/pybind11Tools.cmake:100 (set_property):
set_property could not find TARGET pybind11::pybind11. Perhaps it has not yet been created.
就像这个问题一样https://github.com/pybind/pybind11/issues/3388 https://github.com/pybind/pybind11/issues/3388。也许它在新版本中已修复?
???????????????? 升级至2.8.1
新鲜的pybind11是2.8.1,我们升级一下
pybind11/2.8.1: Not found in local cache, looking in remotes...
pybind11/2.8.1: Trying with 'conancenter'...
ERROR: Unable to find 'pybind11/2.8.1' in remotes
好的。人们可以从字里行间看出,它曾经有效,所以也许我们可以降级?
???????????????????? 降级至 2.4.3
如果我需要pybind/2.4.3
代替pybind/2.7.1
in conanfile.txt
I get
fatal error: Python.h: No such file or directory
112 | #include <Python.h>
| ^~~~~~~~~
就像这个问题一样https://github.com/pybind/pybind11/issues/1781 https://github.com/pybind/pybind11/issues/1781。与该问题不同的是,安装 python*-dev 没有帮助。但无论如何,我不想使用旧的 pybind 。
???????????????????????? 尝试测试包中的 conanfile
conancentral 食谱包含一个测试包(https://github.com/conan-io/conan-center-index/tree/master/recipes/pybind11/all/test_package https://github.com/conan-io/conan-center-index/tree/master/recipes/pybind11/all/test_package),在创建包时会自动测试。让我们尝试一下吧!
CMake Error at CMakeLists.txt:13 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one.
我只是绝望吗???
也许吧,但是!我可以:
???? 打造https://github.com/pybind/cmake_example https://github.com/pybind/cmake_example
???? 打造https://github.com/pybind/python_example https://github.com/pybind/python_example
???? 构建 conancentral pybind11 配方!当我将测试包提取到单独的文件夹时,同样会失败。啥啊?? ????