Swig-Python problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matteo

    Swig-Python problems

    Hi, I've got a problem with SWIG and Python2.2.I've installed the
    SWIG1.3.21 releaseunder QNX6.2 platform .I tried to make the exemple
    example.c (in the directory ../Swig/Exemple/python/simple)
    /* File : example.c */

    #include <time.h>
    double My_variable = 3.0;

    int fact(int n) {
    if (n <= 1) return 1;
    else return n*fact(n-1);
    }

    int my_mod(int x, int y) {
    return (x%y);
    }

    char *get_time()
    {
    time_t ltime;
    time(&ltime);
    return ctime(&ltime);
    }.
    After the commans:

    swig -python example.i
    gcc -c example.c example_wrap.c -I/usr/local/python2.2
    ld -shared example.o example_wrap.o -o _example.so

    I use Python module as follows
    [color=blue][color=green][color=darkred]
    >>> import example[/color][/color][/color]

    and I've got the message: "Memory falut (core dumped)"
    What can I do??
  • Joe Mason

    #2
    Re: Swig-Python problems

    In article <cdb8761d.04031 50739.5de0fee4@ posting.google. com>, matteo wrote:[color=blue]
    > Hi, I've got a problem with SWIG and Python2.2.I've installed the
    > SWIG1.3.21 releaseunder QNX6.2 platform .I tried to make the exemple
    > example.c (in the directory ../Swig/Exemple/python/simple)
    > /* File : example.c */
    >
    > #include <time.h>
    > double My_variable = 3.0;
    >
    > int fact(int n) {
    > if (n <= 1) return 1;
    > else return n*fact(n-1);
    > }
    >
    > int my_mod(int x, int y) {
    > return (x%y);
    > }
    >
    > char *get_time()
    > {
    > time_t ltime;
    > time(&ltime);
    > return ctime(&ltime);
    > }.
    > After the commans:
    >
    > swig -python example.i
    > gcc -c example.c example_wrap.c -I/usr/local/python2.2
    > ld -shared example.o example_wrap.o -o _example.so
    >
    > I use Python module as follows
    >[color=green][color=darkred]
    > >>> import example[/color][/color]
    >
    > and I've got the message: "Memory falut (core dumped)"
    > What can I do??[/color]

    I've found on Linux that it's easy to run the entire Python interpreter
    under a debugger. I'm not familiar with the tools on QNX, but I would
    add "-g" to the gcc line (to add debugging symbols), and then run "gdb
    python", so that when the program crashes you can see exactly where.

    (If you're not familiar with gdb, type "run" at the first prompt, and
    then use the interpreter as normal, and when the crash happens and you
    get back to the gdb prompt, type "bt" to get a backtrace. This should
    be all you need to get started.)

    Joe

    Comment

    • Armin Steinhoff

      #3
      Re: Swig-Python problems

      m.finardi@itia. cnr.it (matteo) wrote in message news:<cdb8761d. 0403150739.5de0 fee4@posting.go ogle.com>...[color=blue]
      > Hi, I've got a problem with SWIG and Python2.2.I've installed the
      > SWIG1.3.21 releaseunder QNX6.2 platform .I tried to make the exemple
      > example.c (in the directory ../Swig/Exemple/python/simple)
      > /* File : example.c */
      >
      > #include <time.h>
      > double My_variable = 3.0;
      >
      > int fact(int n) {
      > if (n <= 1) return 1;
      > else return n*fact(n-1);
      > }
      >
      > int my_mod(int x, int y) {
      > return (x%y);
      > }
      >
      > char *get_time()
      > {
      > time_t ltime;
      > time(&ltime);
      > return ctime(&ltime);
      > }.
      > After the commans:
      >
      > swig -python example.i
      > gcc -c example.c example_wrap.c -I/usr/local/python2.2[/color]

      At first ... please use qcc and not gcc.

      qcc -c -fPIC example.c example_wrap.c -I/usr/local/python2.2

      should work ...
      [color=blue]
      > ld -shared example.o example_wrap.o -o _example.so
      >
      > I use Python module as follows
      >[color=green][color=darkred]
      > >>> import example[/color][/color]
      >
      > and I've got the message: "Memory falut (core dumped)"
      > What can I do??[/color]

      ... use Pyrex :)

      Armin Steinhoff

      Comment

      • Pierre Rouleau

        #4
        Re: Swig-Python problems

        matteo wrote:
        [color=blue]
        > Hi, I've got a problem with SWIG and Python2.2.I've installed the
        > SWIG1.3.21 releaseunder QNX6.2 platform .I tried to make the exemple
        > example.c (in the directory ../Swig/Exemple/python/simple)
        > /* File : example.c */
        >
        > #include <time.h>
        > double My_variable = 3.0;
        >
        > int fact(int n) {
        > if (n <= 1) return 1;
        > else return n*fact(n-1);
        > }
        >
        > int my_mod(int x, int y) {
        > return (x%y);
        > }
        >
        > char *get_time()
        > {
        > time_t ltime;
        > time(&ltime);
        > return ctime(&ltime);
        > }.
        > After the commans:
        >
        > swig -python example.i
        > gcc -c example.c example_wrap.c -I/usr/local/python2.2
        > ld -shared example.o example_wrap.o -o _example.so
        >
        > I use Python module as follows
        >[color=green][color=darkred]
        > >>> import example[/color][/color]
        >
        > and I've got the message: "Memory falut (core dumped)"
        > What can I do??[/color]

        What does your interface space file (examplei.i) contain?

        Comment

        Working...