包含Python .h的C++和Apple Fi

2024-04-24 19:40:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的Makefile,我需要将Python.h添加到主.cpp文件。无论我尝试或搜索什么,我似乎都不知道如何使用Makefile正确导入Python.h。我已经正确地安装了python,并且文件的命名也很正确。Python2.7按预期保存在以下文件夹中:/usr/include/python2.7

唯一重要的部分主.cpp在这里我将Python包含在:

#include <Python.h>

我的Makefile当前如下所示:

^{pr2}$

当我在命令行上运行make命令时,我得到以下错误:

main.cpp:26:20: fatal error: Python.h: No such file or directory
 #include <Python.h>

有人能帮我添加Makefile吗?如果有什么帮助的话,我用树莓皮来做这些。在

基于堆栈溢出的类似问题,我已经尝试过这个方法(运行良好但没有帮助):

sudo apt-get install python-dev

Tags: 文件命令行命令文件夹makeincludemainusr
1条回答
网友
1楼 · 发布于 2024-04-24 19:40:47

{{lds}和{cd2}实用程序可以使用^或cd2}获取。在

%> python3-config  cflags
-I/path/to/Python3.6.5/include/python3.6m -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
%> python3-config  ldflags
-L/path/to/Python3.6.5/lib/python3.6/config-3.6m-x86_64-linux-gnu -L/path/to/Python-3.6.5/lib -lpython3.6m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic

在Makefile中,可以这样设置它们:

^{pr2}$

相关问题 更多 >