1

所以我设法在 helloworld C 程序中使用了 Python。

#include <Python.h>
int main(){
printf("This is C\n");
Py_Initialize();
PyRunSimpleString("print('this is python')");
Py_Finalize();
return 1;}

我也必须sudo apt-get install python-dev和 python3-dev 一样。以防万一。

为了编译和运行它,我使用了以下命令:

gcc -c $(python2.7-config --cflags) cprog.c
gcc cprog.o $(/usr/bin/python2.7-config --ldflags)
./a.out

到目前为止一切正常。现在我有来自git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git的 user-mode-linux

我需要能够从arch/um/drivers/ubd_kern.c. 但是,当我什至插入#include <Python.h>并尝试用它编译所有内容时,make V=1 ARCH=um它会失败。

看来用户模式 ​​linux 有一个-nostdinc标志。所以我尝试链接 Python.h 文件并添加CFLAGS_ubd_kern.o := -DTEST77 -I/home/alli/pyhack $(shell python2.7-config --cflags)到,arch/um/drivers/Makefile但随后编译导致多个冲突。

如何从 user-mode-linux 的驱动程序中使用 Python?提前致谢。

4

0 回答 0