Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go install creates directory os_arch - select different output directory

Tags:

go

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?

like image 653
topskip Avatar asked Sep 15 '25 16:09

topskip


2 Answers

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 the arm tool on an x86 system.
The host system type is 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.

In any case (GOARCH or GOHOSTARCH), the go command will install in a fixed location that you cannot change.

like image 180
VonC Avatar answered Sep 17 '25 08:09

VonC


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

like image 29
Volker Avatar answered Sep 17 '25 08:09

Volker