【发布时间】:2021-12-19 17:22:32
【问题描述】:
我正在尝试编译一个使用Python.h 执行一些python 脚本的C++ 程序。在添加 python 之前,我有一个运行良好的 makefile。我添加了运行python脚本的代码,其中包括Python.h文件。
我编辑了 makefile 以包含这个文件,但没有成功。
我的生成文件:
CC = g++
SHELL = /bin/sh
EXECUTABLES = Software_V2
CFLAGS += -O2 -g0 -Wall -pedantic -Wstrict-prototypes -std=c99 $(shell python3-config --cflags)
LIBS = -lm -lrt -laes_access -lstdc++ -pthread
OBJS = $(EXECUTABLES).o
.PHONEY: all
all: $(EXECUTABLES)
.PHONEY: clean
clean:
rm -f *.[bo]
rm -f *.err
rm -f $(EXECUTABLES)
$(EXECUTABLES): $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(LIBS) -o $@
我已经安装了以下库:
sudo apt-get install python-devsudo apt-get install python3-devsudo apt install libpython3.7-dev
运行make后的错误我收到以下错误:
g++ -c -o Software_V2.o Software_V2.cpp
Software_V2.cpp:3:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.
make: *** [<builtin>: Software_V2.o] Error 1
我还尝试将包含从 #include <Python.h> 更改为 #include <python3.7m/Python.h>
我的尝试都没有成功,我现在没有灵感去尝试一些新事物,也许你们知道如何解决我的问题。谢谢!
【问题讨论】:
-
检查 python3-config --cflags 是否符合您的预期。检查 -I 目录以确保文件位于其中一个目录中。