Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/cgo: error linking against static libraries #3755
This bug involves a fairly simple usage. There are three parts to this program: 1) A static library (named libhello.a) written in C, exposing function "say_hello". 2) A package in Go (named hello), exposing func "SayHello", which calls into the C library. 3) A tool using the hello package (named hello_main) that calls SayHello. The strange part is that when I compile the static library with -g -O2 -fPIC -m64 -pthread -fno-common, the build succeeds.... but fails with a runtime error: panic: runtime error: call of nil func value [signal 0xb code=0x1 addr=0x0 pc=0x0] goroutine 1 [syscall]: hello._Cfunc_say_hello(0x2018, 0xb1a2) /var/folders/p_/mhydwmzj78n6s6xvf9zly6bm0000gn/T/go-build218171681/hello/_obj/_cgo_defun.c:42 +0x2f hello.SayHello() /var/folders/p_/mhydwmzj78n6s6xvf9zly6bm0000gn/T/go-build218171681/hello/_obj/hello.cgo1.go:10 +0x18 main.main() /Users/duane/Projects/go-bug/src/hello_main/hello_main.go:6 +0x18 goroutine 2 [syscall]: created by runtime.main /Users/duane/repo/go/src/pkg/runtime/proc.c:221 However, if I move the c file in with the go package "hello" directory, and allow it to be compiled in without going through the static library intermediary, it runs fine. The two build trees are attached for reference. Simple cd into the directory and "bash ./build.sh" to compile and run it. As for my system: I'm running at tip ("go version weekly.2012-03-27 +95dddad64860") on OSX Lion 10.7.3. GCC is version "i686-apple-darwin11-llvm-gcc-4.2"; however, switching to "vanilla" gcc or to clang makes no effect.
Just ran into this too on linux/amd64 if that makes sense. https://groups.google.com/d/topic/golang-nuts/N68cEF1GdTQ/discussion https://groups.google.com/d/topic/golang-nuts/ZHJV1H99Uzs/discussion