duanbiaojin8860 2018-06-18 13:56
浏览 440
已采纳

如何在Windows 10上交叉编译Go程序

I want to compile a Go programm for a linux machine. I always used that way which is described here:

How to cross compile from Windows to Linux?

That worked pretty well until the last big update from Windows 10. Now I am not able to set the GOOS with

set GOOS=linux

I also tried to start the PowerShell as administrator, but even that is not working. Are there any tools which can do that? Or is there another way to crosscompile Go program on Windows 10?

  • 写回答

1条回答 默认 最新

  • duandanxiu6965 2018-06-18 15:02
    关注

    set is an internal command of the Windows command line interpreter (cmd.exe).

    If you're using PowerShell, then changing values of environment variables should be done like:

    $Env:<variable-name> = "<new-value>"
    

    For more details, see PowerShell documentation: About Environment Variables

    So to change GOOS, use:

    $Env:GOOS = "linux"
    

    To do a cross-compilation:

    1. Navigate to the folder where the main package is.

    2. Run $Env:GOOS = "linux"

    3. Optionally run $Env:GOARCH = "amd64"

    4. Run go build

    Or you can do it in a single line:

    $Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build
    

    To specify the output file name:

    $Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build -o hello
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?