doumei1955
2019-01-24 22:08 阅读 540
已采纳

Go工具链编译期间如何使用GOARCH和GOOS?

I am trying to reconcile why make.bash accepts GOARCH, GOOS and other target variables when it also supports cross compiling to all supported architectures by default. I am compiling this for amd64/linux but will be using the compiler to cross-compile apps for arm/linux in an embedded context. Buildroot builds Go with the following command

cd /builddir/build/host-go-1.10.2/src && 
    GOROOT_BOOTSTRAP=/builddir/host/lib/go-1.4.3 
    GOROOT_FINAL=/builddir/host/lib/go 
    GOROOT="/builddir/build/host-go-1.10.2" 
    GOBIN="/builddir/build/host-go-1.10.2/bin" 
    GOARCH=arm 
    GOARM=7 
    GOOS=linux 
    CC=/usr/bin/gcc 
    CXX=/usr/bin/g++ 
    GO_ASSUME_CROSSCOMPILING=1 
    CC_FOR_TARGET="/builddir/host/bin/arm-linux-gnueabihf-gcc" 
    CXX_FOR_TARGET="/builddir/host/bin/arm-linux-gnueabihf-g++" 
    CGO_ENABLED=1 
    ./make.bash

Which works and goes on to build other apps just fine. My question is why are these target variables relevant at this stage? Wouldn't that only be relevant to the applications being compiled with this program?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dqp21271 dqp21271 2019-01-24 22:20

    The Go compiler and linker are Go programs. make.bash needs to know which architecture and which operating system to build the Go toolchain for.

    See Downloads - The Go Programming Language for examples of the different architectures and operating systems.

    See Installing Go from source.

    点赞 评论 复制链接分享

相关推荐