gorump icon indicating copy to clipboard operation
gorump copied to clipboard

figure out a way to automatically launch a Go program with `main()` as a guest instead of requiring editing the Go program to `//export` something and writing a matching `.c` stub file

Open eyberg opened this issue 10 years ago • 3 comments

figure out a way to automatically launch a Go program with main() as a guest instead of requiring editing the Go program to //export something and writing a matching .c stub file

eyberg avatar Dec 23 '15 17:12 eyberg

You can do it by using two stubs:

mainstub.c:

int kludge_argc = 1;
char *kludge_argv[] = { "foo", 0 };

int main() {
    rump_pub_lwproc_releaselwp(); /* XXX */
    gomaincaller();
}

gomaincaller.go

package main

import "C"

//export gomaincaller
func gomaincaller() {
    main()
}

No program modification is needed to the original go program. disadvantage is that the need to know where the main package is, as the gomaincaller.go should be in that folder.

yuval-k avatar Mar 06 '16 10:03 yuval-k

yeh - def. worth discussing -- @dstrbad - have any opinions on this?

eyberg avatar Mar 07 '16 16:03 eyberg

Looks good, more elegant. Don't see any other options at the moment, a lot to learn on my end :)

dstrbad avatar Mar 11 '16 07:03 dstrbad