gpt4 book ai didi

c++ - 如何使用 SWIG 在 C++ API 上生成 C 包装器?

转载 作者:IT老高 更新时间:2023-10-28 22:21:30 26 4
gpt4 key购买 nike

我想使用 SWIG 在一些 C++ API 上生成 C 包装器。

来自 SWIG 文档 SWIG and C++ :

6.2 Approach

To wrap C++, SWIG uses a layered approach to code generation. At the lowest level, SWIG generates a collection of procedural ANSI-C style wrappers. These wrappers take care of basic type conversion, type checking, error handling, and other low-level details of the C++ >binding. These wrappers are also sufficient to bind C++ into any target language that supports built-in procedures. In some sense, you might view this layer of wrapping as providing a C library interface to C++.

但是,如果不生成代码以在 Python、Ruby 等语言中使用 API,我看不到任何选项可以做到这一点。我怎样才能只获得 C 包装器?

最佳答案

虽然 SWIG 的主分支无法为 C++ API 生成 C 包装器(问题中引用的 SWIG 文档有点误导),但在 2008 年 Google Summer of Code 期间创建了一个 SWIG 分支,可在 https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd/ 获得就是这样做的。我在这里找到了答案:C++ to C Wrapper using SWIG (for FLTK)

关于c++ - 如何使用 SWIG 在 C++ API 上生成 C 包装器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com