英文:
go install creates directory os_arch - select different output directory
问题
我有一个名为fib
的包的文件夹结构:
$ tree
.
└── src
└── fib
├── fib
│ └── main.go
├── fib.go
└── fib_test.go
(main.go
在main
包中,fib(_test).go
在fib
包中)
GOPATH设置为$PWD/src
,GOBIN设置为$PWD/bin
。当我运行go install fib/fib
时,我在bin
目录中得到一个名为fib
的文件(这是我期望的):
$ tree bin/
bin/
└── fib
但是当我设置GOOS
或GOARCH
时,会创建以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
还是GOHOSTARCH
,go
命令都会安装在一个无法更改的固定位置。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论