How to cross compile from Windows to Linux?

后端 未结 4 1301
[愿得一人]
[愿得一人] 2020-12-01 00:42

I\'ve installed Go 1.2 on a Windows machine, wrote up a dummy program and set the environment variables GOARCH and GOOS to \"AMD64\" and \"linux\"

4条回答
  •  再見小時候
    2020-12-01 01:40

    It tells you it needs all tools built before you can use them.

    If your windows GOARCH is amd64, then you could "build" all required tools by running this small batch programs:

    set GOARCH=amd64
    set GOOS=linux
    go tool dist install -v pkg/runtime
    go install -v -a std
    

    If that succeeds then you should be able to do what you've described (just use amd64, not AMD64 - it is case sensitive).

    If your windows GOARCH is 386, then you would need to build your 386 tools first. You would need to download mingw gcc for that. Do what user2714852 said.

    Here https://golang.org/wiki/WindowsCrossCompiling are similar instructions for linux, perhaps you find them helpful.

    Alex

提交回复
热议问题