我只是写了一个简单的 C 可执行文件来检查是否Python.h
正常工作
#include<Python.h>
#include<stdio.h>
int main()
{
printf("this is a python header file included programm\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
显然,它没有多大作用。但是,当我尝试使用gcc
它进行编译时,出现错误:
#include<Python.h>
#include<stdio.h>
int main()
{
printf("this is a python header file included programm\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我检查了python-dev包已
Python.h
安装或未使用locate
.
foo.c:1:19: fatal error: Python.h: No such file or directory.
Run Code Online (Sandbox Code Playgroud)
我很清楚Python.h
我的系统上有头文件。如何让我的可执行文件正常工作?
squ*_*org 20
您需要确认您的包含
#include <python2.7/Python.h>
Run Code Online (Sandbox Code Playgroud)
或者告诉 gcc 在哪里可以找到 Python.h
gcc -I /usr/include/python2.7/ program.c
Run Code Online (Sandbox Code Playgroud)
您需要向 GCC 提供Python.h
标头的包含路径。这可以通过-I
标志来完成:
gcc -c -I/usr/include/python2.7 sourcefile.c
但是,还有更好的方法:使用pkg-config:
pkg-config --cflags python
这将输出需要传递给 GCC 的标志,以便编译使用 Python 头文件和库的应用程序。
链接时,使用此命令的输出来包含适当的库:
pkg-config --libs python
您甚至可以将这两个步骤与:
gcc `pkg-config --cflags --libs python` sourcefile.c
归档时间: |
|
查看次数: |
33616 次 |
最近记录: |