C语言 gcc : 找不到 Python.h,当它在 /usr/include/python2.7 中时



My C code:

#include<stdio.h>
#include "Python.h"
int main()
{
    printf("Hello World");
    return 0;
}

我已经为python2.7安装了python-dev。此外,Python.h/usr/include/python2.7可用。

gcc myfile.c # Python.h:没有这样的文件或目录

我什至尝试过: gcc -L/usr/include/python2.7/ myfile.c # Python.h:没有这样的文件或目录

我尝试用使用Python.h的pip构建一个python c模块ujson,它能够编译。

我错过了什么/做错了什么?

它应该是-I,而不是-L

gcc -I/usr/include/python2.7 myfile.c

使用

#include <Python.h>

而不是

#include "Python.h"

以包含头文件。Python.h 文件应该是包含的第一个文件。

@see 使用 C 或 C++ 扩展 Python(第 1.1 节注释)

由于 Python 可能会定义一些影响 某些系统上的标准标头,您必须在之前包含 Python.h 包括任何标准标头。

最新更新