C/C++编程调用Python脚本集锦
1.C++调用Python脚本中的函数。这是基于vs的。如果用于纯C++,如Dev C++(这个已经测试通过), BC++B(这个还没测试)。注释掉
//#include "stdafx.h"
将语句:int _tmain(int argc, _TCHAR* argv[])
修改为:int main()。头部代码如下:
//#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <Python.h>
using namespace std;
//int main(int argc, _TCHAR* argv[])
int main(void)
{
}
Python安装为最新版的32位的V3.9.5版。
添加:包含文件的路径,如:D:\Python\Pyth3.9.5\include
添加:链接参数,如:
-ID:\Python\Pyth3.9.5\include
-LD:\Python\Pyth3.9.5\libs
-lpython39
2.Python代码的编译
3.Dev C++中C语言程序调用Python
元·刘因《村居杂诗》
芳芬皆可籍,缓步即吾车[jū];
乘兴三杯酒,随行一策书[xū]。
——智慧人生,始自田园美景。 (一策书(湘岳阳万江波))。
蒲公《咏史》
良马非不骏,盐坂徒悲鸣。
美玉非不贵,抱璞为世轻。
高士卧隆中,畴乃知其名?
从容起南阳,谈笑魏吴惊。
男儿事蚕桑,后世有何称?
——智慧世界,源自码农寒士。(一策书(湘岳阳万江波))。