SWIG 接口文件问题

发布于 2024-09-03 15:44:03 字数 495 浏览 2 评论 0原文

我正在为其他语言编写 C/C++ 扩展模块,并使用 SWIG 来生成绑定。

我有两个问题

  1. 我可以在接口文件的声明部分包含超过1个头文件吗,例如:

    /* 暴露给包装器的声明:*/

    <前><代码>> %{ > #定义 SWIG_FILE_WITH_INIT > #包括“啊” > #包括“bh” > #include“ch”%}
  2. 在到目前为止我看到的所有示例中,之后标头包含声明(如上所示),标头中声明的函数然后在接口文件中再次声明。这真的有必要吗,因为这意味着需要维护函数声明的两个副本。

注意:我可以理解,某些函数/方法声明可能需要用“newobject”声明进行“装饰”,因此这些显然需要位于接口文件中,以避免内存泄漏 - 但是,我尽管包含标题就足够了,然后仅包含需要用“newobject”声明的函数/方法的声明 - 这是推荐的做事方式吗?

I am writing a C/C++ extension module for other languages and I am using SWIG to generate the bindings.

I have two questions

  1. Can I include more than 1 header file in the declaration part of the interface file e.g.:

    /* Declarations exposed to wrapper: */

    > %{
    > #define SWIG_FILE_WITH_INIT
    > #include "a.h"
    > #include "b.h"
    > #include "c.h" %}
    
  2. In all of the examples I have seen so far, after the header include declaration (as shown above), the functions declared in the header are then declared again in the interface file. Is this really necessary, as it means there are two copies of the function declarations that need to be maintained.

Note: I can appreciate that some functions/methods declaration may need to be 'decorated' with the 'newobject' declaration so these obviously need to be in the interface file, to avoid memory leaks - however, I would have though that it would be sufficient to include the headers and then ONLY the declarations of the functions/methods that need to be declared with 'newobject' - is this recommended way of doing things?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不喜欢何必死缠烂打 2024-09-10 15:44:03
  1. 是(参见 http://www.swig.org/Doc1.1/HTML /Library.html
  2. 否(参见 http://www.swig.org/tutorial。 html ;寻找 SWIG 来寻找真正的懒人
  1. Yes ( see http://www.swig.org/Doc1.1/HTML/Library.html )
  2. No ( see http://www.swig.org/tutorial.html ; look for SWIG for the truly lazy )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文