在C/C ++中使用Python代码 [英] Use Python code in C/C++

查看:82
本文介绍了在C/C ++中使用Python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在嵌入式Linux环境中工作,我有一些我想使用的Python代码.我的Python代码只是在做一些数学运算,没有使用除Numpy和普通库以外的任何库.

I'm working in an embedded Linux environment and I have some Python code which I would like to use. My Python code is just doing some math, not using any library other than Numpy and the common ones.

有什么方法可以建立可以从C或C ++代码调用的库吗?

Is there any way to build up a library that I can call from C or C++ code?

推荐答案

将CPython解释器嵌入C或C ++程序实际上非常简单.

Embedding the CPython interpreter into a C or C++ program is actually pretty straightforward.

官方文档具有一些完整的示例.

The official documentation has some complete examples.

另外,请检出 SWIG

Also, check out SWIG and Boost.Python.

这篇关于在C/C ++中使用Python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆