Go install creates the os_arch directory - choose a different output directory
I have this folder structure for my package fib
:
$ tree . └── src └── fib ├── fib │ └── main.go ├── fib.go └── fib_test.go
( main.go
in the package main
, fib(_test).go
in the package fib
)
GOPATH is set to $PWD/src
, GOBIN is set to $PWD/bin
. When I run go install fib/fib
I get a file named fib
in the directory bin
(which is what I expect):
$ tree bin/ bin/ └── fib
But when I install GOOS
or GOARCH
, a directory is created in the form GOOS_GOARCH
:
$ GOARCH=386 GOOS=windows go install fib/fib
$ tree bin/
bin/
└── windows_386
└── fib.exe
This is not what I want. I would like to have the file fib.exe
in a directory bin
and not a subdirectory bin/windows_386
.
(How) is it possible?
source to share
This is not possible as shown in issue 6201 .
GOARCH
specifies the type of the binary file.
You might be doing cross compilation:GOARCH
might be hand.
You definitely don't want to run the toolarm
on the systemx86
.
The host system type:GOHOSTARCH
.To install the api tool (or any tools) you need to use
GOARCH=$(go env GOHOSTARCH) go install .../api
and then plain '
go tool
' will find them.
Either way ( GOARCH
or GOHOSTARCH
) the command go
will be installed in a fixed location that you cannot change.
source to share
The phrase "I (don't want to) want" is incompatible with the go tool; go tool works, how it works. You can: a) copy the file to wherever you want after installing it with the go tool, or b) compile it yourself, eg. by calling 6g manually (you can specify the output here). If you are not happy with how the go tool works, just switch to the build tool of your liking, for example. plain old Makefiles. Note that the go tool helps you there for example. by calling the compiler withgo tool 6g
source to share