简体   繁体   English

如何使用swig为c ++生成php界面

[英]How to use swig to generate php interface for c++ so

I have tried a hundred things and I can not get my .so file to interface with php using swig. 我已经尝试了一百件事,我无法使用swig将我的.so文件与php连接。 I can generate the files, then I had to compile Zend and link with that to make the .so but it keeps seg faulting on load now. 我可以生成文件,然后我必须编译Zend并与之链接以生成.so但它现在保持加载段错误。

Can some one please walk me though how to use swig to generate a PHP interface for a C++ library? 有人可以告诉我如何使用swig为C ++库生成PHP接口吗? The documentation on the swig web site is not helpful. swig网站上的文档没有帮助。

I was stuck in the same situation but then the answer by Gaius clarified that the example.i file must be created first, it is not just a fancy parameter to tell swig the name of your project. 我遇到了同样的情况但是Gaius的回答澄清了必须先创建example.i文件,告诉swig你的项目名称不仅仅是一个奇特的参数。 Paragraph 2.3.1 of that guide ! 该指南第2.3.1段 tells what this example.i file is about. 告诉我这个example.i文件的内容。

/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
extern double My_variable;
extern int    fact(int);
extern int    my_mod(int n, int m);
%}

extern double My_variable;
extern int    fact(int);
extern int    my_mod(int n, int m);

This example seems informative. 这个例子看起来很有用。 Have you tried it? 你试过吗?

Hi Double check the permissions of the folder your PHP Code residing. 您好请仔细检查PHP代码所在文件夹的权限。 I faced the same problem. 我遇到了同样的问题。 In fact I was doing some file read/write stuff too in the same directory and I had to set permission to my php project accordingly , otherwise it used to say No Data Received and when I see in apache error log I see Segmentation Fault. 事实上我在同一个目录中也做了一些文件读/写的东西,我不得不相应地设置我的php项目的权限,否则它曾经说过没有数据接收 ,当我在apache错误日志中看到时,我看到Segmentation Fault。

So please check. 所以请检查。 this may help. 这可能有所帮助。

And yes the documentation in Swig site is still not much helpful for PHP developers. 是的,Swig站点中的文档对PHP开发人员来说仍然没有多大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM