c++ - 为覆盖 std::exception 的库生成 swig 接口(interface)时出错

标签 c++ swig

我正在尝试为一个库生成一个 swig 接口(interface),该库具有一个继承自 std::exception 的类。我似乎无法让它工作。

这是一个简单的例子。 mylib.h 的代码:

#pragma once

#include <exception>

class CustomException : public std::exception
{

};

这是 mylib.i 的代码:

%module mylib
 %{
 #include "mylib.h"
 %}

/*
Run without anything:
mylib.h:5: Warning 401: Nothing known about base class 'std::exception'. Ignored.
*/

/*
Run with: %include <exception>
mylib.i:11: Error: Unable to find 'exception'
*/

/*
Run with: %include exception.i 
mylib.h:5: Warning 401: Nothing known about base class 'std::exception'. Ignored.
*/

%include "mylib.h"

正如您在 mylib.i 中的评论中看到的那样,swig 似乎很难弄清楚 std::exception 是什么。

最佳答案

使用 %include <std_except.i> :

%module test
%include <std_except.i>
%inline %{
class CustomException : public std::exception
{
};
%}

关于c++ - 为覆盖 std::exception 的库生成 swig 接口(interface)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53010141/

相关文章:

c++ - 在函数签名中一起使用 * 和 &

c++ - 使用删除时检测到堆损坏

c++ - 具有求和界限的重复排列

c++ - 混合来自不同编译器的 C++ 代码

python - SWIG 将参数传递给 python 回调函数

c++ - 为什么 mkdir 的行为在不同的 Linux 发行版上不同?

c++ - 错误 : passing ‘const sdf’ as ‘this’ argument discards qualifiers [-fpermissive]

python - 如何处理Python中被调用库生成的弹出错误提示?

python - SWIG Python undefined symbol 错误

c - 痛饮 ruby "TypeError: Expected argument 0 of type int *, but got Fixnum 0"