英文:
Go language: Change the build folder when running "go run"
问题
在Windows上使用Go时,每当我在控制台执行go run myprog.go
时,Go会在我的C驱动器上的某个随机位置构建一个新的可执行文件。
有没有办法配置它,使其始终将文件构建到特定位置,并且最好也避免名称的随机性?(即,始终构建到D:\Temp\LastBuild.exe)。
我找到了一些信息,但在执行go help run
和go help build
时没有帮助。后者有一个输出标志-o outfile
,但在go run
中不被接受。
感谢任何帮助。
英文:
Using Go on Windows, whenever I execute go run myprog.go
from the console, Go builds a new executable with a random name somewhere on my C drive.
Is there a way to configure it so it will always build the file to a specific location, and preferably to also avoid the randomness of the name? (i.e., always build to D:\Temp\LastBuild.exe).
I was able to find some info that did not help when doing go help run
and go help build
. The latter had an output flag -o outfile
but it is not accepted in go run
.
Any help is appreciated.
答案1
得分: 2
不要使用go run
。它适用于快速测试代码片段,代码行数不超过一个屏幕的大小。
工作方法如下:
- 编辑代码。
- 运行
go build
。 - 运行可执行文件,它将具有可预测的名称。
- 转到步骤(1)。
如果您与实现同时编写测试(应该这样做),则步骤如下:
- 编辑代码。
- 编辑测试套件。
- 运行
go test
。 - 转到步骤(1)。
请参阅邮件列表上的最新讨论以获取更多关于同一主题的见解。
英文:
Do not use go run
. It's intended for quick testing out snippets of code the size of a single screenful of lines.
The working approach is
- Edit the code.
go build
it.- Run your executable which will have predictable name.
- Go to step (1).
If you write tests in parallel with the implementation (and you should), this changes to
- Edit the code.
- Edit the test suite.
go test
it.- Go to step (1).
Please see this recent thread on the mailing list for more insight on the same subject.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论