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. 参考以下文章:

https://github.com/golang/go/issues/18156
使用最新发行的 release-branch.go1.4, ,方法可以参考如下:

$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

或者下载该包:
https://storage.googleapis.com/golang/go1.4-bootstrap-20161024.tar.gz

你可能感兴趣的:(go)