Last active
November 11, 2016 23:50
-
-
Save Perelandric/133e3e1fa3d35cc9d1d371f3ef1627f1 to your computer and use it in GitHub Desktop.
Statically link to pony library from Go project.
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
package main | |
/* | |
#cgo CFLAGS: -I${SRCDIR}/lib | |
#cgo CFLAGS: -I$PONYHOME/src/libponyrt/ | |
#cgo LDFLAGS: ${SRCDIR}/lib/libtest.a | |
#cgo LDFLAGS: -L$PONYHOME/build/release -lponyrt | |
#cgo LDFLAGS: -lpthread | |
#cgo LDFLAGS: -ldl | |
#include "pony.h" | |
#include "lib/test.h" | |
*/ | |
import "C" | |
import ( | |
"time" | |
"unsafe" | |
) | |
func main() { | |
// Initialize | |
const argc = 1 | |
var argv = [argc]*C.char{C.CString("test")} | |
C.pony_init(argc, unsafe.Pointer(&argv)) | |
// Create actor and arg | |
var t = C.Test_Alloc() | |
var str = C.CString("test") | |
// Call constructor with string | |
C.Test_tag_create_oo__send(t, str) | |
C.pony_start(true) | |
// Wait a second | |
time.Sleep(time.Second) | |
} | |
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
actor @Test | |
new create(s:Pointer[U8] tag) => | |
None |
Some gdb
info:
(gdb) run Starting program: .../test/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff73dc700 (LWP 7723)] [New Thread 0x7ffff6bdb700 (LWP 7724)] [New Thread 0x7ffff5bd9700 (LWP 7726)] [New Thread 0x7ffff63da700 (LWP 7725)] Program received signal SIGSEGV, Segmentation fault. 0x00000000004604e0 in ponyint_gc_done () (gdb) bt #0 0x00000000004604e0 in ponyint_gc_done () #1 0x00000000004574fe in Test_tag_create_oo__send () #2 0x000000000045739c in _cgo_e3a49bdcc536_Cfunc_Test_tag_create_oo__send (v=0xc420055ed0) at .../test/test.go:72 #3 0x00000000004533d0 in runtime.asmcgocall () at /usr/local/go/src/runtime/asm_amd64.s:590 #4 0x00000000004082bd in runtime.cgocall (fn=0x7fffffffd9e0, arg=0x6b7dc0 , ~r2=-9776) at /usr/local/go/src/runtime/cgocall.go:115 #5 0x00000000006b7e00 in runtime.g0 () #6 0x00007fffffffd9e0 in ?? () #7 0x00000000006b7dc0 in ?? () #8 0x00007fffffffd9d0 in ?? () #9 0x000000000042ea14 in runtime.mstart () at /usr/local/go/src/runtime/proc.go:1096 #10 0x0000000000451535 in runtime.rt0_go () at /usr/local/go/src/runtime/asm_amd64.s:156 #11 0x0000000000000001 in ?? () #12 0x00007fffffffdae8 in ?? () #13 0x0000000000000001 in ?? () #14 0x00007fffffffdae8 in ?? () #15 0x0000000000000000 in ?? ()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
C.CString()
produces a*C.char
, which is what the generated C function receives, but it segfaults.There's no problem if I eliminate the string argument or change it to another type, like
bool
.