您的位置:首页 > 编程语言 > C语言/C++

C++嵌入Python最简例

2006-08-04 13:09 274 查看
最简单的内嵌Python例子,完全照搬手册上的例子:

#include <Python.h>

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 <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: