考虑以下几点hello.c:
#include <stdio.h>
int main(int argc, char* argv[]) {
printf("Hello, world! argv[0]=%s\n", argv[0]);
}
Makefile 只包含一行:all: hello. 我如何围绕 Go 程序包装(和编译)这个函数,就像在这个(非工作)示例中一样?
package main
// int main(int argc, char* argv[]);
import "C"
func main() {
argc := C.int(1);
argv := make([]*C.char, 1)
argv[0] = C.CString("hai");
C.main(argc, &argv[0])
}
我得到的错误是:
(virtualenv)[14:16:21][/tmp/cgo]$ ./main
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x1c000000000 pc=0x41d563]
runtime stack:
runtime.throw(0x48b400, 0x2a)
/usr/lib/golang/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
/usr/lib/golang/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.mHeap_Grow(0x6c7c20, 0x8, 0x0)
/usr/lib/golang/src/runtime/mheap.go:647 +0x243
runtime.mHeap_AllocSpanLocked(0x6c7c20, 0x1, 0x0)
/usr/lib/golang/src/runtime/mheap.go:532 +0x5f1
runtime.mHeap_Alloc_m(0x6c7c20, 0x1, 0x15, 0x0)
/usr/lib/golang/src/runtime/mheap.go:425 +0x1ac
runtime.mHeap_Alloc.func1()
/usr/lib/golang/src/runtime/mheap.go:484 +0x41
runtime.systemstack(0x7ffcb3aab958)
/usr/lib/golang/src/runtime/asm_amd64.s:278 +0xab
runtime.mHeap_Alloc(0x6c7c20, 0x1, 0x10000000015, 0x40a954)
/usr/lib/golang/src/runtime/mheap.go:485 +0x63
runtime.mCentral_Grow(0x6d0898, 0x0)
/usr/lib/golang/src/runtime/mcentral.go:190 +0x93
runtime.mCentral_CacheSpan(0x6d0898, 0x6c1180)
/usr/lib/golang/src/runtime/mcentral.go:86 +0x4d4
runtime.mCache_Refill(0x7fbc9971d050, 0x15, 0x40ca28)
/usr/lib/golang/src/runtime/mcache.go:118 +0xcf
runtime.mallocgc.func2()
/usr/lib/golang/src/runtime/malloc.go:611 +0x2b
runtime.systemstack(0x7ffcb3aabb28)
/usr/lib/golang/src/runtime/asm_amd64.s:278 +0xab
runtime.mallocgc(0x180, 0x476220, 0x0, 0x800000000)
/usr/lib/golang/src/runtime/malloc.go:612 +0x842
runtime.newobject(0x476220, 0x6c0c40)
/usr/lib/golang/src/runtime/malloc.go:760 +0x42
runtime.malg(0x8000, 0x6c0e40)
/usr/lib/golang/src/runtime/proc1.go:2188 +0x27
runtime.mpreinit(0x6c1180)
/usr/lib/golang/src/runtime/os1_linux.go:197 +0x1f
BIG阳
相关分类