Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use swig to generate php interface for c++ so

Tags:

c++

php

swig

I have tried a hundred things and I can not get my .so file to interface with php using swig. 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.

Can some one please walk me though how to use swig to generate a PHP interface for a C++ library? The documentation on the swig web site is not helpful.

like image 323
Lodle Avatar asked Feb 03 '09 09:02

Lodle


2 Answers

This example seems informative. Have you tried it?

like image 131
Assaf Lavie Avatar answered Nov 18 '22 09:11

Assaf Lavie


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. Paragraph 2.3.1 of that guide! tells what this example.i file is about.

/* 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);
like image 33
oromoiluig Avatar answered Nov 18 '22 10:11

oromoiluig