在C程序中集成Python

测试环境:Ubuntu 10.04

[code language=”c”]
#include
#include int main(int argc, char * argv[])
{
// initialize the interpreter
Py_Initialize();
// evaluate some code
PyRun_SimpleString(“import sys\n”);
//ignore line wrap on following line
PyRun_SimpleString(“sys.stdout.write(‘Hello from an embedded Python Script\\n’)\n”);
// shut down the interpreter
Py_Finalize();
return 0;
}
[/code]

编译:
[code language=”bash”]
$gcc Listing1.c -I/usr/include/python2.6 -lpython2.6
[/code]

编译成.so
[code language=”bash”]
$gcc -c -fPIC Listing2.c -I/usr/include/python2.6
$gcc -shared Listing2.o -o libcrypto.so -lpython2.6
[/code]

参考:
1. Embedding Python in Multi-Threaded C/C++ Applications

打赏

《在C程序中集成Python》有一个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注