[TOC]
During compilation, SWIG may generate a variety of warning messages. For example:
在编译期间,SWIG 可能会生成各种警告消息。例如:
example.i:16: Warning 501: Overloaded declaration ignored. bar(double)
example.i:15: Warning 501: Previous declaration is bar(int)
Typically, warning messages indicate non-fatal problems with the input where the generated wrapper code will probably compile, but it may not work like you expect.
通常,警告消息指示输入可能发生的非致命问题,生成的包装程序代码可能会通过编译,但可能无法按预期工作。
All warning messages have a numeric code that is shown in the warning message itself. To suppress the printing of a warning message, a number of techniques can be used. First, you can run SWIG with the -w
command line option. For example:
所有警告消息都有一个数字代码,显示在警告消息本身中。可以使用多种技术禁止打印警告消息。首先,你可以使用
-w
命令行选项运行 SWIG。例如:
% swig -python -w501 example.i
% swig -python -w501,505,401 example.i
Alternatively, warnings can be suppressed by inserting a special preprocessor pragma into the input file:
或者,可以通过在输入文件中插入特殊的预处理器编译指令来抑制警告:
%module example
#pragma SWIG nowarn=501
#pragma SWIG nowarn=501,505,401
Finally, code-generation warnings can be disabled on a declaration by declaration basis using the %warnfilter
directive. For example:
最后,可以使用
%warnfilter
指令在逐个声明的基础上禁用代码生成警告。例如:
%module example
%warnfilter(501) foo;
...
int foo(int);
int foo(double); // Silently ignored.
The %warnfilter
directive has the same semantics as other declaration modifiers like %rename
, %ignore
and %feature
, see the %feature directive section. For example, if you wanted to suppress a warning for a method in a class hierarchy, you could do this:
%warnfilter
指令与其他声明修饰符(如%rename
、%ignore
和%feature
)具有相同的语义,请参见%feature
指令部分。例如,如果你想取消对类层次结构中方法的警告,则可以执行以下操作:
%warnfilter(501) Object::foo;
class Object {
public:
int foo(int);
int foo(double); // Silently ignored
...
};
class Derived : public Object {
public:
int foo(int);
int foo(double); // Silently ignored
...
};
Warnings can be suppressed for an entire class by supplying a class name. For example:
通过提供类名称,可以抑制整个类的警告。例如:
%warnfilter(501) Object;
class Object {
public:
... // All 501 warnings ignored in class
};
There is no option to suppress all SWIG warning messages. The warning messages are there for a reason---to tell you that something may be broken in your interface. Ignore the warning messages at your own peril.
没有禁止所有 SWIG 警告消息的选项。出现警告消息是有原因的——告诉你接口中的某些内容可能“损坏”。忽略警告消息,后果自负。
Some warning messages are disabled by default and are generated only to provide additional diagnostics. These warnings can be turned on using the -Wextra
option. For example:
默认情况下,某些警告消息是禁用的,并且仅用于提供其他诊断信息而生成。可以使用
-Wextra
选项打开这些警告。例如:
% swig -Wextra -python example.i
To selectively turn on extra warning messages, you can use the directives and options in the previous section--simply add a "+" to all warning numbers. For example:
要有选择地打开其他警告消息,可以使用上一节中的指令和选项——只需在所有警告编号上添加一个
+
即可。例如:
% swig -w+309,+452 example.i
or in your interface file use either
或者,在你的接口文件中使用
#pragma SWIG nowarn=+309,+452
or
再或
%warnfilter(+309,+452) foo;
Note: selective enabling of warnings with %warnfilter
overrides any global settings you might have made using -w
or #pragma
.
You can of course also enable all warnings and suppress a select few, for example:
注意:使用
%warnfilter
选择性启用警告会覆盖你可能使用-w
或#pragma
进行的所有全局设置。当然,你也可以启用所有警告,并选择关闭某些警告,例如:
% swig -Wextra -w309,452 example.i
The warnings on the right take precedence over the warnings on the left, so in the above example -Wextra
adds numerous warnings including 452, but then -w309,452
overrides this and so 452 is suppressesed.
If you would like all warnings to appear, regardless of the warning filters used, then use the -Wall
option. The -Wall
option also turns on the extra warnings that -Wextra
adds, however, it is subtely different. When -Wall
is used, it also disables all other warning filters, that is, any warnings suppressed or added in %warnfilter
, #pragma SWIG nowarn
or the -w
option.
右边的警告优先于左边的警告,因此在上面的示例中,
-Wextra
添加了很多警告,包括452
,但随后-w309,452
覆盖了该警告,因此452
被禁止。如果你希望所有警告都出现,无论使用什么警告过滤器,请使用
-Wall
选项。-Wall
选项还打开了-Wextra
添加的额外警告,但是它完全不同。当使用-Wall
时,它也会禁用所有其他警告过滤器,即在%warnfilter,#pragma SWIG nowarn
或-w
选项中禁止或添加的任何警告。
Warning messages can be issued from an interface file using a number of directives. The %warn
directive is the most simple:
可以使用许多指令从接口文件中发出警告消息。
%warn
指令是最简单的:
%warn "900:This is your last warning!"
All warning messages are optionally prefixed by the warning number to use. If you are generating your own warnings, make sure you don't use numbers defined in the table at the end of this section.
The %ignorewarn
directive is the same as %ignore
except that it issues a warning message whenever a matching declaration is found. For example:
所有警告消息都可以选择以警告编号作为前缀。如果要生成自己的警告,请确保不要使用本节末尾表中定义的数字。
%ignorewarn
指令与%ignore
指令相同,不同之处在于,只要找到匹配的声明,它就会发出警告消息。例如:
%ignorewarn("362:operator= ignored") operator=;
Warning messages can be associated with typemaps using the warning
attribute of a typemap declaration. For example:
可以使用类型映射声明的
warning
属性将警告消息与类型映射关联。例如:
%typemap(in, warning="901:You are really going to regret this usage of $1_type $1_name") blah * {
...
}
In this case, the warning message will be printed whenever the typemap is actually used and the special variables will be expanded as appropriate, for example:
在这种情况下,每当实际使用类型映射表时,就会显示警告消息,并且将适当地扩展特殊变量,例如:
example.i:23: Warning 901: You are really going to regret this usage of blah * self
example.i:24: Warning 901: You are really going to regret this usage of blah * stuff
The swigwarn.swg
file that is installed with SWIG contains symbol constants that could also be used in %warnfilter
and #pragma SWIG nowarn
. For example this file contains the following line:
随 SWIG 一起安装的
swigwarn.swg
文件包含符号常量,这些常量也可以在%warnfilter
和#pragma SWIG nowarn
中使用。例如,此文件包含以下行:
%define SWIGWARN_TYPE_UNDEFINED_CLASS 401 %enddef
so SWIGWARN_TYPE_UNDEFINED_CLASS
could be used instead of 401, for example:
所以
SWIGWARN_TYPE_UNDEFINED_CLASS
可以代替401
,例如:
#pragma SWIG nowarn=SWIGWARN_TYPE_UNDEFINED_CLASS
or
或者
%warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Foo;
The ability to suppress warning messages is really only provided for advanced users and is not recommended in normal use. You are advised to modify your interface to fix the problems highlighted by the warnings wherever possible instead of suppressing warnings.
Certain types of SWIG problems are errors. These usually arise due to parsing errors (bad syntax) or semantic problems for which there is no obvious recovery. There is no mechanism for suppressing error messages.
抑制警告消息的功能实际上仅提供给高级用户,在正常使用中不建议使用。建议你尽可能修改接口文件以解决警告突出显示的问题,而不是抑制警告。
某些类型的 SWIG 问题是错误。这些通常是由于解析错误(语法错误)或语义问题(无法明显恢复)引起的。没有抑制错误消息的机制。
Warnings can be handled as errors by using the -Werror
command line option. This will cause SWIG to exit with a non successful exit code if a warning is encountered.
通过使用
-Werror
命令行选项,可以将警告视为错误。如果遇到警告,这将导致 SWIG 以非成功的退出代码退出。
The output format for both warnings and errors can be selected for integration with your favourite IDE/editor. Editors and IDEs can usually parse error messages and if in the appropriate format will easily take you directly to the source of the error. The standard format is used by default except on Windows where the Microsoft format is used by default. These can be overridden using command line options, for example:
可以选择警告和错误的输出格式,以与你喜欢的 IDE 或编辑器集成。编辑器和 IDE 通常可以解析错误消息,并且如果采用适当的格式,则可以轻松地直接将你带到错误源。默认使用标准格式,但在 Windows 上默认使用 Microsoft 格式。这些可以使用命令行选项覆盖,例如:
$ swig -python -Fstandard example.i
example.i:4: Syntax error in input(1).
$ swig -python -Fmicrosoft example.i
example.i(4) : Syntax error in input(1).
-
- Deprecated
%extern
directive.
- Deprecated
-
- Deprecated
%val
directive.
- Deprecated
-
- Deprecated
%out
directive.
- Deprecated
-
- Deprecated
%disabledoc
directive.
- Deprecated
-
- Deprecated
%enabledoc
directive.
- Deprecated
-
- Deprecated
%doconly
directive.
- Deprecated
-
- Deprecated
%style
directive.
- Deprecated
-
- Deprecated
%localstyle
directive.
- Deprecated
-
- Deprecated
%title
directive.
- Deprecated
-
- Deprecated
%section
directive.
- Deprecated
-
- Deprecated
%subsection
directive.
- Deprecated
-
- Deprecated
%subsubsection
directive.
- Deprecated
-
- Deprecated
%addmethods
directive.
- Deprecated
-
- Deprecated
%readonly
directive.
- Deprecated
-
- Deprecated
%readwrite
directive.
- Deprecated
-
- Deprecated
%except
directive.
- Deprecated
-
- Deprecated
%new
directive.
- Deprecated
-
- Deprecated
%typemap(except)
.
- Deprecated
-
- Deprecated
%typemap(ignore)
.
- Deprecated
-
- Deprecated command line option (-runtime, -noruntime).
-
- Deprecated
%name
directive.
- Deprecated
-
- The
nestedworkaround
feature is deprecated.
- The
-
- Unable to find
filename
.
- Unable to find
-
- Could not evaluate expression
expr
.
- Could not evaluate expression
-
- Both includeall and importall are defined: using includeall.
-
- CPP
#warning
,warning
.
- CPP
-
- CPP
#error
,error
.
- CPP
-
- Unexpected tokens after
#directive
directive.
- Unexpected tokens after
-
class
keyword used, but not in C++ mode.
-
- Identifier
name
redefined (ignored).
- Identifier
-
%extend
defined for an undeclared classname
.
-
- Unsupported constant value (ignored).
-
- Bad constant value (ignored).
-
identifier
is private in this context.
-
- Can't set default argument value (ignored)
-
- Namespace alias
name
not allowed here. Assumingname
- Namespace alias
-
- [private | protected] inheritance ignored.
-
- Template
name
was already wrapped asname
(ignored)
- Template
-
- Unnamed nested class not currently supported (ignored).
-
- Unrecognized extern type
name
(ignored).
- Unrecognized extern type
-
identifier
is alang
keyword.
-
- Nothing known about
identifier
.
- Nothing known about
-
- Repeated %module directive.
-
- Specialization of non-template
name
.
- Specialization of non-template
-
- Instantiation of template
name
is ambiguous, instantiationtempl
used, instantiationtempl
ignored.
- Instantiation of template
-
- No access specifier given for base class
name
(ignored).
- No access specifier given for base class
-
- Explicit template instantiation ignored.
-
identifier
conflicts with a built-in name.
-
- Redundant redeclaration of
name
.
- Redundant redeclaration of
-
- Recursive scope inheritance of
name
.
- Recursive scope inheritance of
-
- Named nested template instantiations not supported. Processing as if no name was given to %template().
-
- Nested kind not currently supported (
name
ignored).
- Nested kind not currently supported (
-
- Deprecated
%extend
name used - the kind namename
should be used instead of the typedef namename
.
- Deprecated
-
- operator new ignored.
-
- operator delete ignored.
-
- operator+ ignored.
-
- operator- ignored.
-
- operator* ignored.
-
- operator/ ignored.
-
- operator% ignored.
-
- operator^ ignored.
-
- operator& ignored.
-
- operator| ignored.
-
- operator~ ignored.
-
- operator! ignored.
-
- operator= ignored.
-
- operator< ignored.
-
- operator> ignored.
-
- operator+= ignored.
-
- operator-= ignored.
-
- operator*= ignored.
-
- operator/= ignored.
-
- operator%= ignored.
-
- operator^= ignored.
-
- operator&= ignored.
-
- operator|= ignored.
-
- operator<< ignored.
-
- operator>>ignored.
-
- operator<<= ignored.
-
- operator>>= ignored.
-
- operator== ignored.
-
- operator!= ignored.
-
- operator<= ignored.
-
- operator>= ignored.
-
- operator&& ignored.
-
- operator|| ignored.
-
- operator++ ignored.
-
- operator-- ignored.
-
- operator, ignored.
-
- operator-<* ignored.
-
- operator-< ignored.
-
- operator() ignored.
-
- operator[] ignored.
-
- operator+ ignored (unary).
-
- operator- ignored (unary).
-
- operator* ignored (unary).
-
- operator& ignored (unary).
-
- operator new[] ignored.
-
- operator delete[] ignored.
-
- Nothing known about class
name
. Ignored.
- Nothing known about class
-
- Base class
name
is incomplete.
- Base class
-
- Class
name
might be abstract.
- Class
-
- Deprecated typemap feature (
$source
/$target
).
- Deprecated typemap feature (
-
- Setting const char * variable may leak memory.
-
- Reserved
-
- Can't apply (pattern). No typemaps are defined.
-
- Unable to use type
type
as a function argument.
- Unable to use type
-
- Unable to use return type
type
in functionname
.
- Unable to use return type
-
- Unable to set variable of type
type
.
- Unable to set variable of type
-
- Unable to read variable of type
type
.
- Unable to read variable of type
-
- Unsupported constant value.
-
- Unable to handle type
type
.
- Unable to handle type
-
- Unsupported variable type
type
.
- Unsupported variable type
-
- Overloaded
declaration
not supported (incomplete type checking rule - no precedence level in typecheck typemap for 'type
')
- Overloaded
-
- No 'throw' typemap defined for exception type
type
- No 'throw' typemap defined for exception type
-
- No or improper directorin typemap defined for
type
- No or improper directorin typemap defined for
-
- Thread/reentrant unsafe wrapping, consider returning by value instead.
-
- Unable to use return type
type
in director method
- Unable to use return type
-
- Method
method
usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code:code
- Method
-
- Multiple calls to
method
might be generated due to optimal attribute usage in the out typemap.
- Multiple calls to
-
- Initialization using
std::initializer_list
.
- Initialization using
-
- No directorthrows typemap defined for
type
- No directorthrows typemap defined for
-
- Overloaded declaration ignored.
decl
. Previous declaration isdecl
.
- Overloaded declaration ignored.
-
- Overloaded constructor ignored.
decl
. Previous declaration isdecl
.
- Overloaded constructor ignored.
-
- Can't wrap
identifier
unless renamed to a valid identifier.
- Can't wrap
-
- Function
name
must have a return type. Ignored.
- Function
-
- Variable length arguments discarded.
-
- Can't wrap varargs with keyword arguments enabled.
-
- Adding native function
name
not supported (ignored).
- Adding native function
-
- Declaration of
name
shadows declaration accessible via operator->(), previous declaration of'declaration
'.
- Declaration of
-
- Overloaded method
declaration
effectively ignored, as it is shadowed bydeclaration
.
- Overloaded method
-
- Friend function
name
ignored.
- Friend function
-
- Can't use keyword arguments with overloaded functions.
-
- Overloaded method
declaration
ignored, using non-const methoddeclaration
instead.
- Overloaded method
-
- Can't generate wrappers for unnamed struct/class.
-
-
-
- Overloaded method
declaration
ignored, usingdeclaration
instead.
- Overloaded method
-
-
- Portability warning: File
file1
will be overwritten byfile2
on case insensitive filesystems such as Windows' FAT32 and NTFS unless the class/module name is renamed.
- Portability warning: File
-
%template()
contains no name. Template method ignored:declaration
-
- Base/Derived class
classname1
ofclassname2
is not similarly marked as a smart pointer.
- Base/Derived class
-
- Illegal destructor name
name
. Ignored.
- Illegal destructor name
-
- Use of an illegal constructor name
name
in %extend is deprecated, the constructor name should bename
.
- Use of an illegal constructor name
-
- Use of an illegal destructor name
name
in %extend is deprecated, the destructor name should bename
.
- Use of an illegal destructor name
-
- Wrong name (corrected to
name
). (Ruby).
- Wrong name (corrected to
-
- No jni typemap defined for
type
(Java).
- No jni typemap defined for
-
- No jtype typemap defined for
type
(Java).
- No jtype typemap defined for
-
- No jstype typemap defined for
type
(Java).
- No jstype typemap defined for
-
- Warning for
classname
, basebaseclass
ignored. Multiple inheritance is not supported in Java. (Java).
- Warning for
-
-
- No javafinalize typemap defined for
type
(Java).
- No javafinalize typemap defined for
-
- No javabody typemap defined for
type
(Java).
- No javabody typemap defined for
-
- No javaout typemap defined for
type
(Java).
- No javaout typemap defined for
-
- No javain typemap defined for
type
(Java).
- No javain typemap defined for
-
- No javadirectorin typemap defined for
type
(Java).
- No javadirectorin typemap defined for
-
- No javadirectorout typemap defined for
type
(Java).
- No javadirectorout typemap defined for
-
-
- Covariant return types not supported in Java. Proxy method will return
basetype
(Java).
- Covariant return types not supported in Java. Proxy method will return
-
- No javaconstruct typemap defined for
type
(Java).
- No javaconstruct typemap defined for
-
- Missing JNI descriptor in directorin typemap defined for
type
(Java).
- Missing JNI descriptor in directorin typemap defined for
-
- "directorconnect" attribute missing in
type
"javaconstruct" typemap. (Java).
- "directorconnect" attribute missing in
-
- The nspace feature is used on
type
without -package. The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package. (Java).
- The nspace feature is used on
-
- No ctype typemap defined for
type
(C#).
- No ctype typemap defined for
-
- No cstype typemap defined for
type
(C#).
- No cstype typemap defined for
-
- No cswtype typemap defined for
type
(C#).
- No cswtype typemap defined for
-
- Warning for
classname
, basebaseclass
ignored. Multiple inheritance is not supported in C#. (C#).
- Warning for
-
-
- No csfinalize typemap defined for
type
(C#).
- No csfinalize typemap defined for
-
- No csbody typemap defined for
type
(C#).
- No csbody typemap defined for
-
- No csout typemap defined for
type
(C#).
- No csout typemap defined for
-
- No csin typemap defined for
type
(C#).
- No csin typemap defined for
-
-
-
-
- Covariant return types not supported in C#. Proxy method will return
basetype
(C#).
- Covariant return types not supported in C#. Proxy method will return
-
- No csconstruct typemap defined for
type
(C#).
- No csconstruct typemap defined for
-
- C# exception may not be thrown - no
$excode
or excode attribute intypemap
typemap. (C#).
- C# exception may not be thrown - no
-
- Unmanaged code contains a call to a SWIG_CSharpSetPendingException method and C# code does not handle pending exceptions via the canthrow attribute. (C#).
-
- Warning for
classname
: Basebaseclass
ignored. Multiple inheritance is not supported in PHP. (Php).
- Warning for
-
- Unrecognized pragma
pragma
. (Php).
- Unrecognized pragma
These numbers can be used by your own application.
这些数字可被你自己的应用程序使用。
The ability to control warning messages was first added to SWIG-1.3.12.
SWIG-1.3.12 中首次添加控制警告信息的功能。