How to cross compile my Go program from Mac OS X to 64-bit Ubuntu

As the title says, I am wondering how to cross-compile my program so that I can run it on a 64-bit version of Ubuntu

I went into the folder /usr/local/go/srcand ran

GOOS=linux GOARCH=amd64 ./make.bash --no-clean

everything compiled fine

then I went into my project directory and started go build -v -a, and then took the compiled binary and moved it to my Linux server, but when I start, I get this error:

root@PanicCSGO40:~/test# ./test
-bash: ./test: cannot execute binary file: Exec format error
root@PanicCSGO40:~/test# sudo ./test
./test: 1: ./test: Syntax error: "(" unexpected
root@PanicCSGO40:~/test#

Not sure what I'm doing wrong, any information would be greatly appreciated.

I also tried to do this with help GOARCH=386, but still getting the same errors. Thanks!

, , - bash, , , , .

+4
1

:

$ GOOS=linux GOARCH=amd64 go build -v /path/to/target/package
+20

Source: https://habr.com/ru/post/1607216/


All Articles