Skip to content

Instantly share code, notes, and snippets.

@PeterMartini
Last active August 26, 2015 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterMartini/4906760a378d93606203 to your computer and use it in GitHub Desktop.
Save PeterMartini/4906760a378d93606203 to your computer and use it in GitHub Desktop.
Notes for XS + go
hello_from_go.go:
```go
package main
import "C"
import "fmt"
//export hello_from_go
func hello_from_go() {
fmt.Println("Hello from Go")
}
func main() {}
```
Makefile.PL:
```perl
use 5.016;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'hello',
VERSION_FROM => 'hello.pm',
LIBS => ['-L/home/pmartini/tmp -lhello_from_go'],
);
```
hello.pm:
```perl
package hello;
require Exporter;
our $VERSION = '0.01';
our @ISA = qw(Exporter);
require XSLoader;
XSLoader::load('hello', $VERSION);
1;
```
Commands:
```
pmartini@pmlinlaptop:~/tmp$ go build -buildmode=c-shared -o libhello_from_go.so hello_from_go.go
pmartini@pmlinlaptop:~/tmp$ perl Makefile.PL
pmartini@pmlinlaptop:~/tmp$ make
pmartini@pmlinlaptop:~/tmp$ perl -Mblib -Mhello -e 'hello::xsgo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment