Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: error linking against static libraries #3755

Closed
gopherbot opened this issue Jun 19, 2012 · 11 comments
Closed

cmd/cgo: error linking against static libraries #3755

gopherbot opened this issue Jun 19, 2012 · 11 comments

Comments

@gopherbot
Copy link

by Bailey.D.R:

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.

Attachments:

  1. go-bug.tar (8704 bytes)
  2. go-working.tar (8192 bytes)
@gopherbot
Copy link
Author

Comment 1 by Bailey.D.R:

Also: I'm using amd64, so using 6c, 6g, 6l, etc.

@gopherbot
Copy link
Author

Comment 2 by Bailey.D.R:

Also: compiling the same static library into a dynamic library and linking against it
works, too.

@minux
Copy link
Member

minux commented Jun 19, 2012

Comment 3:

which go version do you use?
(go version could tell you that)

Status changed to WaitingForReply.

@minux
Copy link
Member

minux commented Jun 19, 2012

Comment 4:

seems a ld problem on Mac OS X, will investigate.
(sorry for the last comment, i overlooked your version statement)

Status changed to New.

@minux
Copy link
Member

minux commented Jun 19, 2012

Comment 5:

the short answer is: our linker doesn't support static linking.
after CL 5822049 went in, your use case will be supported.
but I still have a remaining issue for that CL on Linux/ARM.

@gopherbot
Copy link
Author

Comment 6 by Bailey.D.R:

Ok. That CL has been referenced for at least a few weeks ago, and someone (somewhere on
the internet) said that tip had it.
Good to know it's still being worked on.

@alberts
Copy link
Contributor

alberts commented Aug 15, 2012

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 8:

4069 should make this possible and trivial.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 9:

Labels changed: added priority-later, removed priority-triage.

@robpike
Copy link
Contributor

robpike commented Sep 22, 2012

Comment 10:

Issue #4130 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented Mar 11, 2013

Comment 11:

We will support this by making the system linker do the final link. This is issue #4069.

Status changed to Duplicate.

Merged into issue #4069.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants