swig -go

Working through the Go SWIG tutorial :

Using two files: example.c and example.i
 /* 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);
 } 

______________________________________________ 
/* 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(); 

________________________________________________________ 
Then, according to the instructions in http://www.swig.org/Doc2.0/Go.html#Go 
% swig -go example.i
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
% 6g example.go
% 6c example_gc.c 

example_gc.c:14 6c: No such file or directory: runtime.h 

After reading golang-nuts thread:

% 6c -I ${GOROOT}/pkg/${GOOS}_${GOARCH} 
-D_64BIT example_gc.c

This works.  


No comments:

Post a Comment