Hello everyone
I am trying to use a module , which I have create by using Swig. This module has C code with embedded Python . The relative code follows :
[CODE=c]
// main.c
#include "Python.h"
#include <stdio.h>
int main()
{
Py_Initialize() ;
PyRun_SimpleStr ing("execfile(' aplo.py') \n");
Py_Finalize();
return 0;
}[/CODE]
# aplo.py //this only print a string
[CODE=python]
print "hello, everything goes well."[/CODE]
[CODE=i]
/* example.i
%module example
%{
#include "Python.h"
int main();
%}
#include "Python.h"
int main();
[/CODE]
To wrap the aboves at a module I use Swig and by executing the following commands:
$ swig -python example.i
$ gcc -c example_wrap.c main.c -Dmain=oldmain -I/usr/include/python2.5
$ ld -shared example_wrap.o main.o -o _example.so
And then from command line i call python:
$ python
>>> import _example
>>>_example.mai n()
hello, everything goes well.
Segmentation fault (core dumped)
And the above message display.
What am I doing wrong ? Is there any solution ?
I appreciate any answer.
Thanks a lot
I am trying to use a module , which I have create by using Swig. This module has C code with embedded Python . The relative code follows :
[CODE=c]
// main.c
#include "Python.h"
#include <stdio.h>
int main()
{
Py_Initialize() ;
PyRun_SimpleStr ing("execfile(' aplo.py') \n");
Py_Finalize();
return 0;
}[/CODE]
# aplo.py //this only print a string
[CODE=python]
print "hello, everything goes well."[/CODE]
[CODE=i]
/* example.i
%module example
%{
#include "Python.h"
int main();
%}
#include "Python.h"
int main();
[/CODE]
To wrap the aboves at a module I use Swig and by executing the following commands:
$ swig -python example.i
$ gcc -c example_wrap.c main.c -Dmain=oldmain -I/usr/include/python2.5
$ ld -shared example_wrap.o main.o -o _example.so
And then from command line i call python:
$ python
>>> import _example
>>>_example.mai n()
hello, everything goes well.
Segmentation fault (core dumped)
And the above message display.
What am I doing wrong ? Is there any solution ?
I appreciate any answer.
Thanks a lot
Comment