ubuntu10.04下c程序中集成python

测试环境:ubuntu 10.04

#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;}

编译:

$gcc listing1.c -i/usr/include/python2.6 -lpython2.6

编译成.so

$gcc -c -fpic listing2.c -i/usr/include/python2.6$gcc -shared listing2.o -o libcrypto.so -lpython2.6

发表评论