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 :
Expand|Select|Wrap|Line Numbers
- // main.c
- #include "Python.h"
- #include <stdio.h>
- int main()
- {
- Py_Initialize();
- PyRun_SimpleString("execfile('aplo.py') \n");
- Py_Finalize();
- return 0;
- }
Expand|Select|Wrap|Line Numbers
- print "hello, everything goes well."
Expand|Select|Wrap|Line Numbers
- /* example.i
- %module example
- %{
- #include "Python.h"
- int main();
- %}
- #include "Python.h"
- int main();
$ 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.main()
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