最简单的内嵌Python例子,完全照搬手册上的例子:
#include
int
main(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
#define _DEBUG
#else
#include
#endif