profile
viewpoint

Ask questionscmd/link: showing many ld warnings of "building for macOS, but linking in object file"

<!-- Please answer these questions before submitting your issue. Thanks! -->

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

<pre> $ go version go1.12.7 darwin/amd64 </pre>

Does this issue reproduce with the latest release?

yes

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

Mac Mojave 10.14.5

Result of go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/avence12/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/avence12/.gvm/pkgsets/go1.12.7/global:/Users/avence12/devel/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/avence12/.gvm/gos/go1.12.7"
GOTMPDIR=""
GOTOOLDIR="/Users/avence12/.gvm/gos/go1.12.7/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/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-build525129295=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Install and use go1.12.7 by GVM
  2. Get into my project and run go build ./...
  3. The build is successful but seeing lots of ld warning. The same situation when I run go test ./...
  4. When I setup export CGO_ENABLED=0, the warning is gone. However I would like to know how to resolve the issue.

What did you expect to see?

No ld warnings when CGO_ENABLED=1

What did you see instead?

$ go build ./cmd/...
# github.com/avence12/myproj/cmd/client
ld: warning: building for macOS, but linking in object file (/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-link-703159202/go.o) built for 
# github.com/avence12/myproj/cmd/server
ld: warning: building for macOS, but linking in object file (/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-link-846047020/go.o) built for 
golang/go

Answer questions thanm

I tried looking at the Apple sources for the linker, but unfortunately they don't seem to have released source code for this version of the linker. The closest I could find was version 409; in that source base there is a somewhat similar error message here at line 2181 but I don't think this is the scenario: from looking at the code that only triggers when using bitcode, and if it does trigger it's a fatal error and not a warning. Too bad we don't have up-to-date source to look at.

useful!

Related questions

cmd/link: segmentation fault during mach-o linking hot 4
cmd/go: cannot find module providing package error stops `go get` processing hot 3
cmd/go: needs a better error than "missing dot in first path element" when GOROOT is set incorrectly hot 2
x/xerrors: fails to compile on tip hot 1
vendor/golang.org/x/xerrors/adaptor_go1_13.go:16:14: undefined: errors.Frame ... hot 1
cmd/go: `go clean <package>` downloads modules hot 1
cmd/cgo error: runtime: unknown pc 0x7fff5c805b86 hot 1
runtime: crash with "invalid pc-encoded table" hot 1
cmd/vet: potential false positive in the "suspect or" check hot 1
runtime: go program crach, it seems fall into infinite loop hot 1
cmd/go: major version without preceding tag must be v0, not v1 - breaks build of github.com/go-check hot 1
runtime: macOS Sierra builders spinning hot 1
cmd/go: Problem using go modules hot 1
cmd/go: "unrecognized import path" for local packages after updating to go1.13 hot 1
cmd/go: "found, but does not contain package" error refers to replaced version instead of its replacement hot 1
Github User Rank List