-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: Allow skipping link phase of go build #9675
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
Comments
You need to run the Go linker. That is what creates the .o files you want. Before the link step, the Go code is compiled into a Go-specific format that the system linker will not recognize. The error you see is coming from the external linker. You don't care what the external reports, since you are going to do your own link. So just run something like "go build -ldflags=-extld=/bin/true". |
Hi @ianlancetaylor, thanks for the response. That looks like a good idea, unfortunately
|
I get the same error whether I pass -ldflags=-extld=true. Even if I pass it nonsense flags:
|
(sorry, accidentally submitted before finishing) Even if I pass it those nonsense flags it produces the same error. It's clearly quitting before it ever calls the external linker. |
That is a failure while handling a Go file that uses import "C". The go tool runs a small link in order to see which symbols will be defined by shared libraries. This link normally succeeds because the final link normally succeeds. We can't skip this link, though. We need to know that information in order to generate correct Go code in general. I don't think there is any clean way to handle this. Perhaps you could provide dummy definitions of your symbols and #cgo LDFLAGS to pick up the dummy definitions. I don't know whether that would work or not. |
Yep, my current workaround involves telling
|
I'm using Go in a somewhat unusual way in an Xcode Objective C/C++ project – I'm collecting the
.o
files out ofgo build
's temp dir to produce a static library usingar
. The static library is then linked into my project by Xcode's normal build process.The goal of this system is to allow the majority of my project to be built in Xcode like it always has, but have the Go portion built by
go build
. This means I'd like Xcode to link the Go static library with the rest of my codebase.So I have
go build
just compiling my Go code, solely so I can get those.o
files – and that part works great. The problem is,go build
fails during the link phase, because it's missing the C symbols used in my Go code via Cgo andimport "C"
. It makes sense that the Go linker can't find these symbols, because they only exist in object files in Xcode's intermediate files dir.So, I'd love to be able to tell
go build
to skip the link phase, since I don't actually need the fully linked binary, and thus the link failure is not meaningful.In case it helps clarify, here's the output from
go build
:You can see that it can't find
iosmain()
, which is defined in a separatemain.m
which I don't want Go to see or compile.The text was updated successfully, but these errors were encountered: