为重写std::exception的库生成swig接口时出错

Error generating swig interface for library which overrides std::exception

本文关键字:swig 接口 出错 重写 std exception      更新时间:2023-10-16

我正试图为一个库生成一个swig接口,该库具有从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
{
};
%}