I have this folder structure for my fib
package:
$ tree
.
└── src
└── fib
├── fib
│ └── main.go
├── fib.go
└── fib_test.go
(main.go
is in package main
, fib(_test).go
is in 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 called fib
in the directory bin
(this is what I expect):
$ tree bin/
bin/
└── fib
But when I set GOOS
or GOARCH
, the directory in the form GOOS_GOARCH
is created:
$ GOARCH=386 GOOS=windows go install fib/fib
$ tree bin/
bin/
└── windows_386
└── fib.exe
This is not what I want. I'd like to have the file fib.exe
in the bin
directory, not in the sub directory bin/windows_386
.
(How) is this possible?
That doesn't seem possible, as illustrated in issue 6201.
GOARCH
sets the kind of binary to build.
You might be cross-compiling:GOARCH
might be arm.
You definitely don't want to run thearm
tool on anx86
system.
The host system type isGOHOSTARCH
.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.
In any case (GOARCH
or GOHOSTARCH
), the go
command will install in a fixed location that you cannot change.
The phrase "I (don't) want" is incompatible with the go tool; the go tool works how it works. You can a) copy the file to where you want it to be after installing it with the go tool or b) compile it yourself, e.g. by invoking 6g manually (here you can specify the output). If you are unhappy with how the go tool works, just switch to a build tool of your liking, e.g. plain old Makefiles. Note that the go tool helps you there too, e.g. by invoking the compiler via go tool 6g