我正在使用 Golang 和 cgo。當我的 C 代碼引發 . 時assert(),我無法在使用cgo.相反,我看到了捕獲斷言的 golang 運行時的堆棧跟蹤。這是我的 C 代碼示例#include <stdio.h>#include <pthread.h>#include <assert.h>#include <string.h>void fn2(char *arg){ int stackvar2 = 256; printf("Argument %s\n", arg); assert(1 == 2);}void fn1(int arg){ int stackvar3 = 512; char var[256]; strcpy(var, "deadbeef"); fn2(var);}void *thread(void *arg){ printf("Hello from the thread... going in for an assert\n"); fn1(1092); return NULL;}void hello_world(char *str){ pthread_t tid; printf("Hello World from C and here the str is from Go: %s\n", str); pthread_create(&tid, NULL, thread, NULL); sleep(100000);}Here is my Go codepackage main/*extern void hello_world(char *str);#cgo LDFLAGS: -L. -lhello#cgo CFLAGS: -g3*/import "C"import ( _ "fmt")func main() { str := "From Golang" cStr := C.CString(str) C.hello_world(cStr) select {}}這是我的 Makefileall: gcc -g3 -O0 -c hello.c ar cru libhello.a hello.o go build hello.goclean: rm -f *.o hello
- 2 回答
- 0 關注
- 274 瀏覽
添加回答
舉報
0/150
提交
取消