Open
Description
What version of Go are you using (go version
)?
$ go version go1.12.7 darwin/amd64
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?
- Install and use go1.12.7 by GVM
- Get into my project and run
go build ./...
- The build is successful but seeing lots of ld warning. The same situation when I run
go test ./...
- 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Triage Backlog
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Showing many ld warnings of "building for macOS, but linking in object file" [/-][+]cmd/link: showing many ld warnings of "building for macOS, but linking in object file" [/+]ianlancetaylor commentedon Jul 22, 2019
CC @randall77 @thanm
ianlancetaylor commentedon Jul 22, 2019
Which version of XCode do you have installed?
thanm commentedon Jul 22, 2019
Is that the complete warning (e.g. "built for" and then nothing more)? Wondering if the output got truncated somehow.
avence12 commentedon Jul 23, 2019
@ianlancetaylor:
I did not install XCode when I saw the issue. After I install
XCode Version 10.2.1
, the issue remains.@thanm:
I add the result of
go env
and complete warning to origin message. There is nothing after "built for".juev commentedon Jul 23, 2019
The same issue for me.
xuhrc commentedon Jul 24, 2019
ld: warning: building for macOS, but linking in object file (/var/folders/78/6hfbqt9x3z3bvm41rhn81smhx0t1sf/T/go-link-034794354/go.o) built for
same issue for me
The warning disappeared after i installed command line tools beta 6
thanm commentedon Jul 24, 2019
I'm not having any luck reproducing this.
I'm working with a MacOS 10.14.5 macbook, Xcode 10.3, installed go 1.12.7 using "gvm", but when I build the projects above I don't see any warnings.
It might help to know what version of the linker you're working with, since it's the linker issuing the warning.
Please try this small experiment: run clang on a tiny C file to invoke the linker, then using the linker path you see in the output, run "ld -v" to see what version it claims to be:
juev commentedon Jul 24, 2019
thanm commentedon Jul 24, 2019
Thanks @juev . Looks like your linker is more or less the same vintage as mine, so nothing notable there.
I also tried deleting Xcode from my Mac and to just the downloaded command line tools, but that didn't help.
How about this as another possible experiment to try: redo the link with -tmpdir set, which should capture the object files feeding into the external linker, then run 'file' on one of the ones the linker is complaining about to see what it looks like. Demo:
avence12 commentedon Jul 25, 2019
@thanm My ld is the same as your version.
Another test:
One thing may be related, the
gcc
version:4 remaining items
caseylucas commentedon Aug 7, 2019
I was having the same problem:
when using:
After upgrading to "Command Line Tools for Xcode 11 Beta 5" (available at https://developer.apple.com/download/more/) the problem went away:
thanm commentedon Aug 9, 2019
@avence12 , @caseylucas thanks for finding those workarounds.
oshankkumar commentedon Aug 30, 2019
I am also facing a similar issue
jacob-carlborg commentedon Oct 12, 2019
I ran into the same issue with the D compiler.
The issue is that the linker is looking for a load command in each object file which contains the platform, platform version and SDK version. Clang outputs this load command but the D compiler doesn't. I'm guessing the Go compiler isn't outputting this load command either. I'm guessing the output looks cut off because the linker doesn't find this load command and therefore prints nothing.
I'm guessing the linker is doing this to verify that the all the object files being linked are compatible. The linker can also make sure that all features are supported by the target platform. For example, if thread local storage are being used but targeting macOS 10.6 (TLS was added in 10.7) the linker will fail to link the executable.
Have a look at the
build_version_command
struct in themach-o/loader.h
header file.Clivern commentedon Feb 22, 2023
I see something similar. still looking for the main cause!
$ sw_vers ProductName: macOS ProductVersion: 13.2 BuildVersion: 22D49 $ go version go version go1.19 darwin/amd64 # command-line-arguments ld: warning: -no_pie is deprecated when targeting new OS versions ld: warning: non-standard -pagezero_size is deprecated when targeting macOS 13.0 or later