extend python with C embedded python+ Swig

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nimitsis
    New Member
    • Aug 2007
    • 16

    extend python with C embedded python+ Swig

    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
    Last edited by bartonc; Oct 5 '07, 07:43 PM.
  • nimitsis
    New Member
    • Aug 2007
    • 16

    #2
    Hello again
    Did anyone knows if Swig support wrapping C code with embedded Python code? To do that is any special declarations that I have to introduce at interface file ?

    Comment

    Working...