1. 程式人生 > >Go1.4 編譯失敗:unknown relocation type 42; compiled without -fpic?

Go1.4 編譯失敗:unknown relocation type 42; compiled without -fpic?

ubuntu x86_64 編譯Go1.4.3失敗:

net/rpc
net/rpc/jsonrpc
# cmd/pprof
/home/user/go/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
/home/user/go/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
runtime/cgo(.text): unexpected relocation type
298
runtime/cgo(.text): unexpected relocation type 298 # cmd/go /home/user/go/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic? /home/user/go/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic? runtime/cgo(.text): unexpected relocation type
298
runtime/cgo(.text): unexpected relocation type 298

**

解決辦法:

**

  1. 設定環境變數不使能cgo:
export  CGO_ENABLED=0

然後在執行編譯指令碼。

  1. 參考以下文章:
$git clone https://github.com/golang/go.git
$ cd go
$ git branch -r
  origin/HEAD -> origin/master
  origin/dev.boringcrypto
  origin/dev.boringcrypto.go1.8
  origin/dev.cc
origin/dev.debug origin/dev.garbage origin/dev.gcfe origin/dev.inline origin/dev.power64 origin/dev.ssa origin/dev.tls origin/dev.typealias origin/master origin/release-branch.go1 origin/release-branch.go1.1 origin/release-branch.go1.2 origin/release-branch.go1.3 origin/release-branch.go1.4 origin/release-branch.go1.5 origin/release-branch.go1.6 origin/release-branch.go1.7 origin/release-branch.go1.8 origin/release-branch.go1.9 origin/release-branch.r57 origin/release-branch.r58 origin/release-branch.r59 origin/release-branch.r60 $ git checkout origin/release-branch.go1.4