Using
http://gcc.gnu.org/onlinedocs/gccgo/Function-Names.html#Function-Names
i've been able to make a shared library written in Go:
-----main.go------
package main
func Myfunc () int32 {
return 1
}
------------------
it's linked like this:
gccgo -shared main.go -o libmain.so -lgcc
and is used by this C program:
-----main.c-----
#include <stdio.h>
extern int Myfunc () __asm__ ("go.main.Myfunc");
int main (int argc, char **argv)
{
int tmp;
printf ("Calling the function\n");
tmp = Myfunc ();
printf ("Called the function, got %d\n", tmp);
return 0;
}
---------------
which is linked like this:
gcc -g -O0 main.c -o main -L. -lmain
and when i run it like that:
LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./main
it works.
However, if i put anything more complex than "return 1" into Myfunc in
Go (such as using fmt.Printf() or returning a string - with appropriate
prototype changes to 'string' and 'char*' in Go and C, naturally), it
segfaults at runtime.
Is that a limitation of gccgo, a bug, or am i simply doing something wrong?