缺少Python.h头文件

Jam*_*son 3 c python gcc header-files

我正在试图弄清楚如何在C中编译Python模块(http://docs.python.org/extending/extending.html),但似乎缺少Python.h头文件.

我已经安装了所有python开发头文件(我有Python-dev,python2.7-dev,python2.6-dev,python-all-dev)但是gcc仍在重新编译错误:

fatal error: Python.h: No such file or directory

compilation terminated.
Run Code Online (Sandbox Code Playgroud)

知道我哪里错了吗?还有一个参数我需要为Python.h添加到gcc(它是什么?).

Geo*_*edy 8

您需要使用它python-config来确定编译时间和链接时间标志.

编译时:

gcc -c `python-config --cflags` somefile.c
Run Code Online (Sandbox Code Playgroud)

链接时:

gcc -o libfoo.so -shared `python-config --ldflags`
Run Code Online (Sandbox Code Playgroud)

虽然您真的应该考虑使用distutils,如使用distutils 构建C和C++扩展中所述