doucu7330
2016-05-12 16:33
浏览 101

从源代码构建go编译器时出错

I am trying to build the latest version (tip of the master branch) of Go from source.

The official Go documentation (https://golang.org/doc/install/source) states that you should download Go 1.4 binaries to build a more recent version. However it should be possible to build all from source.

To do this, I set variables in .bashrc :

PATH="$HOME/go/bin:$PATH"
export GOPATH=$HOME

then to build go 1.4 from source :

source ~/.bashrc
git clone https://go.googlesource.com/go
mkdir ~/go1.4
cd ~/go
git archive --format=tar go1.4.3 |tar -xv -C ~/go1.4
cd ~/go1.4/src
./make.bash

and finally build the latest version :

cd ~/go/src/
GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash

I remember doing this months ago without problems, but today I get these errors building go 1.4 make.bash:

# cmd/pprof
.../go1.4/pkg/linux_amd64/runtime/cgo.a(_all.o): unknown relocation type 42; compiled without -fpic?
.../go1.4/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
...

Is there something wrong in my method ?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试从源代码构建Go的最新版本(主分支的提示)。

Go官方文档( https://golang.org/doc/install/source )指出,您应该下载Go 1.4二进制文件以构建更新版本。 但是应该可以从源代码构建所有内容。

为此,我在 .bashrc 中设置变量:

  PATH =“ $ HOME / go / bin:$ PATH” 
export GOPATH = $ HOME 
   
 
 

然后从源代码构建go 1.4:

 源〜/ .bashrc 
git克隆https://go.googlesource.com/go
mkdir〜/ go1.4 
cd〜/ go 
git存档--format =  tar go1.4.3 | tar -xv -C〜/ go1.4 
cd〜/ go1.4 / src 
./make.bash 
   
 
 

构建最新版本:

  cd〜/ go / src / 
GOROOT_BOOTSTRAP = $ HOME / go1.4 ./make.bash
   
 
 

我记得几个月前这样做没问题,但今天我在构建1.4 make.bash 时遇到了这些错误:

   #cmd / pprof 
 ... / go1.4 / pkg / linux_amd64 / runtime / cgo.a(_all.o):未知的重定位类型42;  
 ... / go1.4 / pkg / linux_amd64 / runtime / cgo.a(_all.o)编译时不带-fpic ?:未知的重定位类型42;  
runtime / cgo(.text):意外重定位类型298 
runtime / cgo(.text):意外重定位类型298 
 ... 
   
 
  

我的方法有问题吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyin8809 2016-05-12 20:08
    已采纳

    The error messages point to CGO, and environment variables that control make.bash are explained at the beginning of the file :

    CGO_ENABLED: Controls cgo usage during the build. Set it to 1 to include all cgo related files, .c and .go file with "cgo" build directive, in the build. Set it to 0 to ignore them.

    so if you disable CGO while building GO 1.4 :

    cd ~/go1.4/src
    CGO_ENABLED=0 ./make.bash
    

    everything works and pass the tests.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题