什么是SWIG的警告503
What is Warning 503 by SWIG?
请解释一下SWIG的这些警告是什么以及如何避免它?
Warning 503: Can't wrap 'operator ()' unless renamed to a valid identifier.
Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier.
Warning 503: Can't wrap 'operator *' unless renamed to a valid identifier.
当 SWIG 生成的代码C++在 Android NDK 下编译时,会生成警告。
与C++相同的operator()
或operator=
,因此SWIG无法直接包装它。因为它们可能很重要,所以会显示一条警告,说明它们没有被包裹。(缺少operator=
有时可能特别糟糕)。
此代码在运行swig -Wall -c++ -java
时显示如下警告:
%module Sample
struct test {
bool operator()();
};
但是,您可以静音警告,并告诉 SWIG 将运算符直接公开为常规成员函数,方法是说:
%module Sample
%rename(something_else) operator();
struct test {
bool operator()();
};
这会导致在生成的包装器中添加一个名为 something_else
的函数来代替operator()
。
或者你可以向SWIG断言,忽略这些是很好的:
%ignore operator()
(您还可以通过使用类名限定运算符来不太广泛地应用这些指令中的任何一个)。
在目标语言中使用重载运算符,则需要在 SWIG 中以特殊方式处理重载运算符。看这里。
%rename
指令出现在用于实例化函数的 %template
指令之前,您可能会遇到此警告,如下所示:
%module some_module
%rename("%(undercase)s", %$isfunction) "";
// equivalently %rename("%(utitle)s", %$isfunction) "";
%inline %{
template<class T>
void MyFunction(){}
%}
// ...
%template(MyIntFunction) MyFunction<int>;
警告 503:除非重命名为有效标识符,否则无法包装"my_function
"
而且您不能尝试在%template
中预测重命名:
%template(MyIntFunction) my_function<int>;
因为那样你会得到
错误:模板"myfunction"未定义。
如果您正在应用全局重命名规则,这非常令人沮丧,并且您实际上只需要"忽略重命名"几件事。与类型映射不同,重命名指令始终有效。能够关闭它们会很好,即使是暂时的。
我想出的唯一解决方法是返回到%rename
并将其更新为显式仅匹配(或者更确切地说,不匹配)您内联声明的模板函数。这样:
// don't rename functions starting with "MyFunction"
%rename("%(undercase)s", %$isfunction, notregexmatch$name="^MyFunction") "";
它并不完美,但这是一种解决方法。
(这一切都是在SWIG 4.0中完成的)
- 警告处理为错误这里有什么问题
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- cppcheck在const std::string[]上引发警告
- Python 3.7 和 excess_args 的 SWIG 问题
- GCC对可能有效的代码抛出init list生存期警告
- 如何在BST的这个简单递归实现中消除警告
- 关于std::move的使用,是否有编译警告
- g++ 在某个类成员未初始化时不发出警告
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 使用typeid警告未使用的变量
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 为重写std::exception的库生成swig接口时出错
- 示例C++项目编译中的警告
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 如何修复编译器警告 C6386 和 C6385?
- 返回语句后的代码,没有警告
- Swig:Carrays和Char / char*的警告
- 什么是SWIG的警告503
- (SWIG c++ to Python)警告301:使用了class关键字,但不在c++模式下
- SWIG:如何使用%apply返回结构? 'No typemaps defined'警告