【问题标题】:gcc : Unable to find Python.h, When its there in /usr/includes/python2.7?gcc:无法找到 Python.h,当它在 /usr/includes/python2.7 中时?
【发布时间】:2012-06-12 07:49:10
【问题描述】:

我的 C 代码:

#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,更好的解决方案:编写一个 makefile(是的,这需要一些研究,但努力是值得的)。在命令行上编译可能会很痛苦
  • 如果此代码是 Python 扩展,那就更好了:编写一个 setup.py 文件并使用 distutils。

标签: python c gcc include include-path


【解决方案1】:

应该是-I,而不是-L

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

【讨论】:

    【解决方案2】:

    使用

    #include <Python.h>
    

    而不是

    #include "Python.h"
    

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

    @see Extending Python with C or C++(第 1.1 节注)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      相关资源
      最近更新 更多