PHP-SWIG致命错误:无法重新声明类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP-SWIG致命错误:无法重新声明类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1789字,纯文字阅读大概需要3分钟。
内容图文
![PHP-SWIG致命错误:无法重新声明类](/upload/InfoBanner/zyjiaocheng/657/71fe02ff4b2c4487be897cdb21c8743b.jpg)
我用swig将c类包装在PHP中时遇到问题:
我的课程在头文件中声明如下:
#include <string.h>
using namespace std;
class Ccrypto
{
int retVal;
public:
int verify(string data, string pemSign, string pemCert);
long checkCert(string inCert, string issuerCert, string inCRL);
int verifyChain(string inCert, string inChainPath);
int getCN(string inCert, string &outCN);
};
这些方法中的每一个都包含几个功能.
我的界面文件如下:
%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.so文件,没有任何错误.但是,当我在代码中使用此类时,会遇到此错误:
Fatal error: Cannot redeclare class Ccrypto in /path/to/my/.php file
当我检查Ccrypto.php文件时,我发现Ccryptohas类被声明了两次.我的意思是:
Abstract class Ccrypto {
....
}
和
class Ccrypto {
...
}
为什么SWIG为我的班级生成两个声明?
解决方法:
问题是您有一个与模块同名的类(命令行上为%module或-module). SWIG在C中将自由函数公开为带有模块名称的抽象类的静态成员函数.这是为了模仿我认为的名称空间.因此,生成的PHP将包含两个类,如果您的类与模块同名并且具有任何非成员函数,则该类将为一个抽象.
您可以使用以下方法进行测试:
%module test
%inline %{
class test {
};
void some_function() {
}
%}
产生您报告的错误.
对于SWIG在看到PHP运行时错误之前没有发出警告,我感到有些惊讶.对于生成Java的同一接口,它会给出以下错误:
Class name cannot be equal to module class name: test
有几种可能的方法可以解决此问题:
>重命名模块
>在代码库中重命名该类.
>重命名类(使用%rename):
%module test
%rename (test_renamed) test;
%inline %{
class test {
};
void some_function() {
}
%}
>隐藏免费功能:
%ignore some_function;
内容总结
以上是互联网集市为您收集整理的PHP-SWIG致命错误:无法重新声明类全部内容,希望文章能够帮你解决PHP-SWIG致命错误:无法重新声明类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。