最简单的内嵌Python例子,完全照搬手册上的例子:
#include <Python.h>intmain(int argc, char *argv[]){ Py_Initialize(); PyRun_SimpleString("from time import time,ctime\n" "print 'Today is',ctime(time())\n"); Py_Finalize(); return 0;}注意:
* 需要指定include, lib目录
* 对于g++, 需手工加入python库: -lpython24
* 对于VC, 库会自动加入,但应绕过调试库:
// http://mail.python.org/pipermail/python-list/2002-February/089443.html
#ifdef _DEBUG#undef _DEBUG#include <Python.h>#define _DEBUG#else#include <Python.h>#endif 发表于 @ 2006年08月04日 13:09:00|评论(loading...)