SWIG致命错误:无法重新声明类 我在使用PHIG的PHP中封装C++类有一个问题: 我的类在头文件中声明如下: #包括 使用名称空间std; Ccrypto类 { 内部检索; 公众: int验证(字符串数据、字符串pemSign、字符串pemCert); 长校验证书(字符串输入、字符串发出、字符串输入); int验证链(字符串输入,字符串输入路径); int getCN(字符串输入、字符串和输出); };
这些方法中的每一种都由几个函数组成。SWIG致命错误:无法重新声明类 我在使用PHIG的PHP中封装C++类有一个问题: 我的类在头文件中声明如下: #包括 使用名称空间std; Ccrypto类 { 内部检索; 公众: int验证(字符串数据、字符串pemSign、字符串pemCert); 长校验证书(字符串输入、字符串发出、字符串输入); int验证链(字符串输入,字符串输入路径); int getCN(字符串输入、字符串和输出); };,php,class,swig,declaration,Php,Class,Swig,Declaration,这些方法中的每一种都由几个函数组成。 我的界面文件如下: %module Ccrypto %include <std_string.i> %include "Ccrypto.h" %include "PKI_APICommon.h" %include "PKI_Certificate.h" %include "PKI_Convert.h" %include "PKI_CRL.h" %include "PKI_TrustChain.h" %{ #include "Ccrypto.h"
我的界面文件如下:
%module Ccrypto
%include <std_string.i>
%include "Ccrypto.h"
%include "PKI_APICommon.h"
%include "PKI_Certificate.h"
%include "PKI_Convert.h"
%include "PKI_CRL.h"
%include "PKI_TrustChain.h"
%{
#include "Ccrypto.h"
#include "PKI_APICommon.h"
#include "PKI_Certificate.h"
#include "PKI_Convert.h"
#include "PKI_CRL.h"
#include "PKI_TrustChain.h"
%}
当我检查Ccrypto.php文件时,我发现类Ccrypto
已经声明了两次。我是说我有:
Abstract class Ccrypto {
....
}
及
为什么SWIG会为我的类生成两个声明?问题是您有一个与模块同名的类(
%module
或命令行上的-module)。SWIG将C++中的自由函数公开为具有模块名称的抽象类的静态成员函数。我认为这是为了模仿名称空间。因此,生成的PHP将包含两个类,一个抽象类,如果您使用与模块同名的类,并且具有任何非成员函数
您可以通过以下方法对此进行测试:
%module test
%inline %{
class test {
};
void some_function() {
}
%}
这将生成您报告的错误
我有点惊讶,SWIG在看到PHP运行时错误之前没有发出警告。生成Java时,同一接口会出现以下错误:
类名不能等于模块类名:test
有几种可能的解决方法:
%Rename
):
class Ccrypto {
...
}
%module test
%inline %{
class test {
};
void some_function() {
}
%}
%module test
%rename (test_renamed) test;
%inline %{
class test {
};
void some_function() {
}
%}
%ignore some_function;