gpt4 book ai didi

使用 cmake 和 pybind11 构建示例应用程序时找不到 Python.h

转载 作者:行者123 更新时间:2023-11-28 01:18:25 27 4
gpt4 key购买 nike

我想用 pybind11 构建简单的应用程序,pybind 已经用 cmake(和 make install)安装在我的 Ubuntu 系统中。我使用这个简单的 cmake 文件:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(trt_cpp_loader )
find_package(pybind11 REQUIRED)
add_executable(trt_cpp_loader main.cpp)
set_property(TARGET trt_cpp_loader PROPERTY CXX_STANDARD 11)

这是 main.cpp:

#include <iostream>
#include <pybind11/embed.h>
namespace py = pybind11;

using namespace std;
int main(){return 0;}

当我构建它时,我得到:

In file included from /usr/local/include/pybind11/pytypes.h:12:0,
from /usr/local/include/pybind11/cast.h:13,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/pybind11.h:44,
from /usr/local/include/pybind11/embed.h:12,
from /home/stiv/lpr/trt_cpp_loader/main.cpp:2:
/usr/local/include/pybind11/detail/common.h:112:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.

我该如何解决这个问题? (已经安装了python-dev和python3-dev,Python.h可用)

最佳答案

对于创建扩展模块的默认情况,您需要使用 pybind11_add_module 命令(参见 https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake)。

如果目标确实是将 Python 嵌入到可执行文件中,则您有责任将 Python header 和库显式添加到 CMake 中的编译器/链接器命令。 (参见 https://pybind11.readthedocs.io/en/stable/compiling.html#embedding-the-python-interpreter 如何做到这一点)

关于使用 cmake 和 pybind11 构建示例应用程序时找不到 Python.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57813196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com