简体   繁体   English

使用python编写C ++脚本

[英]Scripting C++ with python

I have a C++ program and I want to implement scripts on it. 我有一个C ++程序,我想在其上实现脚本。 The desired scenario is, I have an executable of c++ code, it then calls at specific times a python script so it knows what to do through the embeded interpreter and the script then uses some form of API from the c++ program. 所需的场景是,我有一个c ++代码的可执行文件,然后在特定时间调用python脚本,因此它知道通过嵌入式解释器做什么,然后脚本使用c ++程序中的某种形式的API。 This is where I ran into a problem. 这是我遇到问题的地方。 To expose c++ code to python you need to compile a DLL of the wrappers that you want and load it as a module inside python and that breaks my intention of python accessing the executable 's functions. 要将c ++代码公开给python,你需要编译你想要的包装器的DLL并将其作为python中的模块加载,这违背了python访问可执行文件函数的意图。

Any way to resolve this problem without resorting to put so much pieces of c++ on a shared library? 有什么方法可以解决这个问题,而无需在共享库上放置如此多的c ++片段?

What you want to do is to embed Python code into your application. 您要做的是将Python代码嵌入到您的应用程序中。 There is an article on python.org on how to do that using raw CPython, but it's not that exhaustive when it comes to C++. python.org上有一篇关于如何使用原始CPython来做到这一点的文章 ,但在C ++方面并不是那么详尽。 A better bet might be to use Boost.Python or SWIG . 更好的选择可能是使用Boost.PythonSWIG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM