从Makefile中指定Python使用Pybind11:“Python.h:没有这样的文件或目录”

问题描述 投票:0回答:1

我正在尝试将 PyBind11 与我的 C++ 程序一起使用,但无法弄清楚如何正确指定 Makefile(我无法在该程序中使用 CMake)。

我的 Makefile 如下所示:

program = mlfe

include $(JIVEDIR)/makefiles/prog.mk
include $(JIVEDIR)/makefiles/packages/*.mk

MY_LIBS += boost_filesystem boost_system
MY_INCDIRS += Eigen

MY_INCDIRS += /home/<username>/.local/lib/python3.10/site-packages/pybind11/include $(shell python3 -m pybind11 --includes)

(我首先从容器中尝试,但失败后我转移到系统 python 安装)

编译时出现以下错误:

example.cpp:137:
/home/<username>/.local/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../detail/common.h:274:10: fatal error: Python.h: No such file or directory
  274 | #include <Python.h>

python3-dev 已正确安装。我还可以编译 pybind11 文档的示例,没有任何错误,让我相信这是我的 Makefile 的问题。

我尝试向 Makefile 添加其他命令,但没有成功:

PYTHON_LIBS = $(shell python3-config --libs)
PYTHON_CFLAGS = $(shell python3-config --cflags)
CXXFLAGS += $(MY_INCDIRS:%=-I%) # $(PYTHON_CFLAGS)
LDFLAGS += $(MY_LIBS) $(PYTHON_LIBS)
makefile compilation pybind11
1个回答
0
投票

感谢@John Bollinger 指出问题所在。我已将以下行添加到 Makefile

MY_INCDIRS += /usr/include/python3.10

这已经解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.