SWIG:%import和%include之间的差异 [英] SWIG: difference between %import and %include

查看:965
本文介绍了SWIG:%import和%include之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SWIG文件会解释这两个指令,如下所示:

The SWIG docs explain these two directives as follows:


  • %include :要将另一个文件包含到SWIG界面,请使用 %include 指令...不同于 #include %include (并且不会在随后的%include 声明中重新加载该文件)。因此,不必在SWIG界面中使用include-guard。

  • %include: "To include another file into a SWIG interface, use the %include directive ... Unlike, #include, %include includes each file once (and will not reload the file on subsequent %include declarations). Therefore, it is not necessary to use include-guards in SWIG interfaces."

%import :SWIG提供了另一个包含%import directive ... %import 的目的是收集来自另一个SWIG接口文件或头文件的某些信息,而不实际生成任何包装器代码,这些信息通常包括类型声明(例如,typedef)以及可能用作接口中类声明的基类的C ++类。

%import: "SWIG provides another file inclusion directive with the %import directive ... The purpose of %import is to collect certain information from another SWIG interface file or a header file without actually generating any wrapper code. Such information generally includes type declarations (e.g., typedef) as well as C++ classes that might be used as base-classes for class declarations in the interface. "

我的问题是这两个指令之间的区别是什么,以及使用每个指令的优缺点是什么?

My question is what are the differences between these two directives and what are the pros/cons of using each?

PS只是一些背景信息。我有一个简单的C ++ - python扩展,构建和工作,当我使用上述任何一个指令。一个,但是(%import )在调用 swig -c ++ -python my_file.i 时会减少警告。

P.S. Just for some background info. I have a simple C++ - python extension that builds and works when I use either of the above directives. One, however (%import) gives fewer warnings when I call swig -c++ -python my_file.i.

推荐答案

SWIG的工作方式是假设您提供的任何有效的C ++声明都暴露给目标语言。因此,提供SWIG的任何C ++代码都将用于生成接口。

The way SWIG works is that it assumes that any valid C++ declarations you provide are to be exposed to the target language. Therefore, any C++ code that SWIG is provided will be used to generate an interface.

%import 防止生成其包括的代码的接口的机制。这是区别。所以,当你包括一个标题时,你问的问题是,我想让这个标题中的所有东西暴露给目标语言?如果答案是否,那么你使用%import

这篇关于SWIG:%import和%include之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆