Go to cross compilation with 1.5.x - the output file is redefined

I am using go 1.5 and I am cross compiling as indicated here .

The problem is that when compiling a project, it overrides the binary file created by the last compilation. Moreover - I will never know which OS / ARCH executable that I am running has been compiled (in any case, these are not windows).

Is there a way to rename a file in a compilation command?

+5
source share
2 answers

You can use the "-o" argument, for example:

 GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o test/output/myapp 
+2
source

From the page you linked to:

-o can be used to change the name and destination of your binary, but remember that the go assembly takes on a value that refers to your $ GOPATH / src and not to your working directory, so changing directories is done with the go build command as an option.

If you use GOOS and GOARCH in the name, you can achieve what you want.

+2
source

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


All Articles