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

标签 c++ c swig

我想使用 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/

相关文章:

c++ - 打印 4 个数字中最大的数字 优化

c++ - 处理点击 3d 对象 opengl

c++ - 从可以导入到 C# 中的 C++/CLI 包装器返回指向非托管类的指针

c++ - 二维数组操作的康威游戏错误

c++ - udp 选择超时问题。超时或从所有客户端读取

使用 memcpy 将数组复制到新数组

c - 位检查的 If 子句替换为使用 C 的位操作

c++ - 用于 Boost 数组的 SWIG/Lua 类型映射

python - SWIG:您能否使用 SWIG 仅使用 C++ 头文件使 C++ 在 Python 中可用?

c - 错误 : array type 'va_list' (aka '__builtin_va_list' ) is not assignable