Skip to content

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

Closed
@tjoery

Description

@tjoery

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions