SWIG problems with gcc and Cygwin?

M

Michael Yanowitz

Hello:

I am just trying out SWIG, but quickly ran into problems.
Using Cygwin gcc, I tried the following:

1) Created example.c (as given on http://www.swig.org/tutorial.html )
/* 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);
}

2) Create interface file, example.i

/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();

3)ran in cygwin: swig -i python example.i

4)Attempted to run on cygwin: ld -shared example.o example_wrap.o -o
_example.so
But got back many errors:
example.o:example.c:(.text+0x55): undefined reference to `time'
example.o:example.c:(.text+0x60): undefined reference to `ctime'
example_wrap.o:example_wrap.c:(.text+0x9c): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x12c): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x1dd): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x494): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x748): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x779): undefined reference to `strcpy'
example_wrap.o:example_wrap.c:(.text+0x7a5): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x805): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x877): undefined reference to
`strncpy'
example_wrap.o:example_wrap.c:(.text+0x8ab): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x8c9): undefined reference to `memset'
example_wrap.o:example_wrap.c:(.text+0x948): undefined reference to `fputs'
example_wrap.o:example_wrap.c:(.text+0x95d): undefined reference to `fputs'
example_wrap.o:example_wrap.c:(.text+0x970): undefined reference to `fputs'
example_wrap.o:example_wrap.c:(.text+0x9db): undefined reference to
`PyString_Fr
omFormat'
example_wrap.o:example_wrap.c:(.text+0xa3a): undefined reference to
`PyString_Fr
omString'
example_wrap.o:example_wrap.c:(.text+0xa68): undefined reference to
`PyLong_From
VoidPtr'
example_wrap.o:example_wrap.c:(.text+0xa83): undefined reference to
`PyTuple_New
etc...

Any idea what I am doing wrong or omitted?

Of course when I then try to go into python and
import example, I get:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "example.py", line 5, in ?
import _example
ImportError: No module named _example

Thanks in advance:
Michael Yanowitz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top