Last active
August 26, 2015 06:00
-
-
Save PeterMartini/4906760a378d93606203 to your computer and use it in GitHub Desktop.
Notes for XS + go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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