<legend id='rEcEL'><style id='rEcEL'><dir id='rEcEL'><q id='rEcEL'></q></dir></style></legend>
      <bdo id='rEcEL'></bdo><ul id='rEcEL'></ul>
  1. <i id='rEcEL'><tr id='rEcEL'><dt id='rEcEL'><q id='rEcEL'><span id='rEcEL'><b id='rEcEL'><form id='rEcEL'><ins id='rEcEL'></ins><ul id='rEcEL'></ul><sub id='rEcEL'></sub></form><legend id='rEcEL'></legend><bdo id='rEcEL'><pre id='rEcEL'><center id='rEcEL'></center></pre></bdo></b><th id='rEcEL'></th></span></q></dt></tr></i><div id='rEcEL'><tfoot id='rEcEL'></tfoot><dl id='rEcEL'><fieldset id='rEcEL'></fieldset></dl></div>
    <tfoot id='rEcEL'></tfoot>

    <small id='rEcEL'></small><noframes id='rEcEL'>

      将 C++ API 暴露给 Python

      Exposing a C++ API to Python(将 C++ API 暴露给 Python)
      <tfoot id='58U79'></tfoot>

            <bdo id='58U79'></bdo><ul id='58U79'></ul>
          • <small id='58U79'></small><noframes id='58U79'>

            <i id='58U79'><tr id='58U79'><dt id='58U79'><q id='58U79'><span id='58U79'><b id='58U79'><form id='58U79'><ins id='58U79'></ins><ul id='58U79'></ul><sub id='58U79'></sub></form><legend id='58U79'></legend><bdo id='58U79'><pre id='58U79'><center id='58U79'></center></pre></bdo></b><th id='58U79'></th></span></q></dt></tr></i><div id='58U79'><tfoot id='58U79'></tfoot><dl id='58U79'><fieldset id='58U79'></fieldset></dl></div>

              • <legend id='58U79'><style id='58U79'><dir id='58U79'><q id='58U79'></q></dir></style></legend>
                  <tbody id='58U79'></tbody>
              • 本文介绍了将 C++ API 暴露给 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前正在处理一个项目,我必须用 Python 包装 C++ 类才能编写程序脚本.所以我的具体经验还涉及在我们的程序中嵌入 Python 解释器.

                I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.

                我尝试的替代方案是:

                • Boost.Python

                • Boost.Python

                我喜欢 Boost.Python 生成的更简洁的 API,但它需要用户安装额外的依赖项这一事实使我们转向了 SWIG.

                I liked the cleaner API produced by Boost.Python, but the fact that it would have required that users install an additional dependency made us switch to SWIG.

                SWIG

                SWIG 对我们的主要优势是它不需要最终用户安装它来使用最终程序.

                SWIG's main advantage for us was that it doesn't require end users to install it to use the final program.

                您过去常常这样做,您对此有何经验?

                What have you used to do this, and what has been your experience with it?

                推荐答案

                我都使用过(用于同一个项目):Boost 与 STL 更好地集成,尤其是 C++ 异常.此外,它的内存管理机制(试图桥接 C++ 内存管理和 Python GC)比 SWIG 更灵活.但是,SWIG 具有更好的文档,没有外部依赖项,如果您将库封装在 SWIG for Python 中,那么您就已经获得了 Java/Perl/Ruby 包装器的一半以上.

                I've used both (for the same project): Boost is better integrated with the STL, and especially C++ exceptions. Also, its memory management mechanism (which tries to bridge C++ memory management and Python GC) is way more flexible than SWIG's. However, SWIG has much better documentation, no external dependencies, and if you get the library wrapped in SWIG for Python you're more than half-way there to getting a Java/Perl/Ruby wrapper as well.

                我认为没有明确的选择:对于较小的项目,我会再次使用 Boost.Python,对于较大的长期项目,对 SWIG 的额外投资是值得的.

                I don't think there's a clear-cut choice: for smaller projects, I'd go with Boost.Python again, for larger long-lived projects, the extra investment in SWIG is worth it.

                这篇关于将 C++ API 暴露给 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                  <tfoot id='gZRyz'></tfoot>

                    <bdo id='gZRyz'></bdo><ul id='gZRyz'></ul>
                  • <small id='gZRyz'></small><noframes id='gZRyz'>

                      <tbody id='gZRyz'></tbody>
                  • <i id='gZRyz'><tr id='gZRyz'><dt id='gZRyz'><q id='gZRyz'><span id='gZRyz'><b id='gZRyz'><form id='gZRyz'><ins id='gZRyz'></ins><ul id='gZRyz'></ul><sub id='gZRyz'></sub></form><legend id='gZRyz'></legend><bdo id='gZRyz'><pre id='gZRyz'><center id='gZRyz'></center></pre></bdo></b><th id='gZRyz'></th></span></q></dt></tr></i><div id='gZRyz'><tfoot id='gZRyz'></tfoot><dl id='gZRyz'><fieldset id='gZRyz'></fieldset></dl></div>

                        <legend id='gZRyz'><style id='gZRyz'><dir id='gZRyz'><q id='gZRyz'></q></dir></style></legend>