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/go: cross-compiling for Linux x86_64 with CGO -race enabled failed on macOS Mojave (Darwin) #30863

Closed
sitano opened this issue Mar 15, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@sitano
Copy link

commented Mar 15, 2019

What version of Go are you using (go version)?

$ go version
1.12
1.12.1

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

MacOS 10.14.3 (18D109) cross-compiling for Linux, AMD64

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2g/3p3p4dn95yn1zzmwjrjjn57w0000gn/T/go-build541165451=/tmp/go-build -gno-record-gcc-switches -fno-common"

What xcode tools installed do you have?

$> clang --version
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What did you do?

$ env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -race

What did you expect to see?

A compiled program

What did you see instead?

/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/2g/3p3p4dn95yn1zzmwjrjjn57w0000gn/T/go-link-142075432/000002.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /var/folders/2g/3p3p4dn95yn1zzmwjrjjn57w0000gn/T/go-link-142075432/000002.o
ld: warning: ignoring file /var/folders/2g/3p3p4dn95yn1zzmwjrjjn57w0000gn/T/go-link-142075432/go.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /var/folders/2g/3p3p4dn95yn1zzmwjrjjn57w0000gn/T/go-link-142075432/go.o
Undefined symbols for architecture x86_64:
  "__cgo_topofstack", referenced from:
      __cgo_7e1b3c2abc8d_C2func_getnameinfo in 000017.o
      __cgo_7e1b3c2abc8d_Cfunc_getnameinfo in 000017.o
      __cgo_7e1b3c2abc8d_C2func_getaddrinfo in 000019.o
      __cgo_7e1b3c2abc8d_Cfunc_gai_strerror in 000019.o
      __cgo_7e1b3c2abc8d_Cfunc_getaddrinfo in 000019.o
      __cgo_7b5af5e1ac14_Cfunc_ZSTD_getErrorName in 000021.o
      __cgo_7b5af5e1ac14_Cfunc_ZSTD_isError in 000021.o
      ...
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [build_linux_dev] Error 2

@sitano sitano changed the title build: cross-compiling for Linux x86_64 with CGO -race enabled failed on a Darwin build: cross-compiling for Linux x86_64 with CGO -race enabled failed on macOS Mojave (Darwin) Mar 15, 2019

@bradfitz bradfitz changed the title build: cross-compiling for Linux x86_64 with CGO -race enabled failed on macOS Mojave (Darwin) cmd/go: cross-compiling for Linux x86_64 with CGO -race enabled failed on macOS Mojave (Darwin) Mar 15, 2019

@bradfitz

This comment has been minimized.

Copy link
Member

commented Mar 15, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 15, 2019

When trying to cross-compile a Go program that uses cgo, you need to have a C cross-compiler. In your case you are building with the C native compiler. That can't work.

@sitano

This comment has been minimized.

Copy link
Author

commented Mar 15, 2019

@ianlancetaylor Yes, I know, I am only confused a little that having cgo only for race detector worked well in all previous Go versions with native compiler (like with 1.11.6)

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 15, 2019

We had to change the way that the Darwin port works, as mentioned at https://golang.org/doc/go1.12#darwin .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.