Skip to content

Instantly share code, notes, and snippets.

@hatajoe
Last active September 28, 2015 14:06
Show Gist options
  • Save hatajoe/4fd972ff1545418867b6 to your computer and use it in GitHub Desktop.
Save hatajoe/4fd972ff1545418867b6 to your computer and use it in GitHub Desktop.
`runtime/cgo: could not obtain pthread_keys' on darwin/amd64
// file: plugins/hello/hello.go
// $ go build -o libhello.so -buildmode=c-shared hello.go
package main
import "C"
import (
"log"
)
//export Hello
func Hello() int {
log.Println("Hello")
return 200
}
func init() {
log.Println("loaded")
}
func main() {
}
// file: main.go
package main
import "C"
import (
"bitbucket.org/binet/go-ffi/pkg/ffi"
"fmt"
)
func main() {
lib, err := ffi.NewLibrary("./plugins/hello/libhello.so")
if err != nil {
panic(err)
}
defer lib.Close()
fn, err := lib.Fct("Hello", ffi.Int, []ffi.Type{})
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", fn().Int())
}
@hatajoe
Copy link
Author

hatajoe commented Sep 28, 2015

here's my environment

~/src/test❯ uname -sv
Darwin Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64
~/src/test❯ go version
go version go1.5.1 darwin/amd64
~/src/test❯ brew info libffi
libffi: stable 3.0.13 (bottled), HEAD
Portable Foreign Function Interface library
https://sourceware.org/libffi/

This formula is keg-only.
Some formulae require a newer version of libffi.

/usr/local/Cellar/libffi/3.0.13 (13 files, 388K)
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/libffi.rb
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Some formulae require a newer version of libffi.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/libffi/lib

~/src/test❯ tree
.
├── main.go
└── plugins
    └── hello
        ├── hello.go
        ├── libhello.h
        └── libhello.so

2 directories, 4 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment