You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat go.mod
module tgo
go 1.13
$ cat main.go
package main
func main() {
}
$ GOOS=linux GOARCH=amd64 go build -buildmode=plugin
$ GOOS=darwin GOARCH=amd64 go build -buildmode=plugin
# tgo
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: -f may not be used without -shared
collect2: error: ld returned 1 exit status
The text was updated successfully, but these errors were encountered:
cagedmantis
changed the title
Cross-compiling a darwin plugin fails to link
cmd/go: cross-compiling a darwin plugin fails to link
Dec 6, 2019
When cross-compiling a plugin to Darwin you must set the environment variable CC to a Darwin cross-compiler. Building a plugin requires invoking the system linker.
What do I put in CC? What counts as a Darwin cross-compiler? Why does invoking the system linker change things? Why does it spit out an error that makes it look like go itself has a bug rather than an informative message?
Cross compiling a pure Go program works as described on that page. But cross-compiling a program that uses cgo, or that uses the build modes c-shared, c-archive, shared, or plugin, requires a C cross-compiler. A cross-compiler is a compiler that runs on your host system (in your case, GNU/Linux) and can compile a C program into a compiler that runs on your target system (in your case, macOS).
Invoking the system linker changes things because you need to use a linker that can produce an executable that runs on the target system.
I agree that the error message could likely be improved. That is #16395.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputDescription of problem
The text was updated successfully, but these errors were encountered: