Skip to content

go 1.13 build error, clang: error: linker command failed with exit code 1. How can i fix it ? #35232

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

Closed
tjoery opened this issue Oct 29, 2019 · 2 comments

Comments

@tjoery
Copy link

tjoery commented Oct 29, 2019

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

$ go version
go version go1.13.3 darwin/amd64

Does this issue reproduce with the latest release?

N/A

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

$sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.4
BuildVersion:	18E226
go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/athapornpongphudphon/Library/Caches/go-build"
GOENV="/Users/athapornpongphudphon/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/Users/athapornpongphudphon/work/golab"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/athapornpongphudphon/work/golab/src/shortenUrl/go.mod"
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/g_/w7965d_x0sq5_fwz9f0nzzy40000gp/T/go-build239942091=/tmp/go-build -gno-record-gcc-switches"
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What did you do?

I'm building a project steps as follows ;

export output_name=$GOPATH/shortenUrl/bin/shortenUrl-linux-amd64

env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=off go build -o=$output_name

But the result was error!!!

What did you expect to see?

building success

What did you see instead?

/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/g_/w7965d_x0sq5_fwz9f0nzzy40000gp/T/go-link-781191658/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/g_/w7965d_x0sq5_fwz9f0nzzy40000gp/T/go-link-781191658/go.o
Undefined symbols for architecture x86_64:
"__cgo_topofstack", referenced from:
__cgo_faadc1275fbb_Cfunc_dpiConn_breakExecution in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_commit in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_getServerVersion in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_newVar in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_ping in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_prepareStmt in 000001.o
__cgo_faadc1275fbb_Cfunc_dpiConn_release in 000001.o
...
"__cgoexp_faadc1275fbb_CallbackSubscr", referenced from:
_CallbackSubscr in 000000.o
"_crosscall2", referenced from:
_CallbackSubscr in 000000.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)

@bcmills
Copy link
Contributor

bcmills commented Oct 29, 2019

Cross-compilation with CGO_ENABLED requires that you set CC to a suitable cross-compiler (with relevant C source files for the target system).

Your command line suggests that you are attempting to build a Linux binary using a macOS host. That generally works fine for pure-Go binaries, but Linux and macOS have very different C environments and toolchains — you might not have appropriate Linux C headers and sources installed, or they might require additional configuration via environment variables.

@bcmills
Copy link
Contributor

bcmills commented Oct 29, 2019

This issue seems to be a question about how to use Go, rather than a feature request or defect report about the Go language and/or toolchain.

We have decided that our experiment to allow questions on the issue tracker has not had the outcome we desired, so I am closing this issue. I'm sorry that we can't answer your question here.

There are many other methods to get help if you're still looking for answers:

Thanks

@bcmills bcmills closed this as completed Oct 29, 2019
@golang golang locked and limited conversation to collaborators Oct 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants