go install创建了os_arch目录-选择不同的输出目录

huangapple go评论72阅读模式
英文:

go install creates directory os_arch - select different output directory

问题

我有一个名为fib的包的文件夹结构:

$ tree 
.
└── src
    └── fib
        ├── fib
        │   └── main.go
        ├── fib.go
        └── fib_test.go

main.gomain包中,fib(_test).gofib包中)

GOPATH设置为$PWD/src,GOBIN设置为$PWD/bin。当我运行go install fib/fib时,我在bin目录中得到一个名为fib的文件(这是我期望的):

$ tree bin/
bin/
└── fib

但是当我设置GOOSGOARCH时,会创建以GOOS_GOARCH形式命名的目录:

$ GOARCH=386 GOOS=windows go install fib/fib
$ tree bin/
bin/
└── windows_386
    └── fib.exe

这不是我想要的。我希望将fib.exe文件放在bin目录中,而不是子目录bin/windows_386中。

这是否可能?

英文:

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?

答案1

得分: 3

这似乎是不可能的,正如问题6201所示。

> GOARCH设置要构建的二进制文件类型。
您可能正在进行交叉编译:GOARCH可能是arm。
您绝对不希望在x86系统上运行arm工具。
主机系统类型是GOHOSTARCH

> 要安装api工具(或任何工具),您需要使用

GOARCH=$(go env GOHOSTARCH) go install .../api

> 然后普通的'go tool'将找到它们。

无论是GOARCH还是GOHOSTARCHgo命令都会安装在一个无法更改的固定位置。

英文:

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.

答案2

得分: 1

翻译结果如下:

短语“我(不)想要”与go工具不兼容;go工具按照其自己的方式工作。你可以选择a)在使用go工具安装后将文件复制到你想要的位置,或者b)自己编译它,例如手动调用6g(在这里你可以指定输出)。如果你对go工具的工作方式不满意,可以切换到你喜欢的构建工具,例如传统的Makefile。请注意,go工具也可以帮助你,例如通过go tool 6g调用编译器。

英文:

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

huangapple
  • 本文由 发表于 2014年11月28日 18:49:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/27187070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定