Go语言:在运行”go run”时更改构建文件夹

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

Go language: Change the build folder when running "go run"

问题

在Windows上使用Go时,每当我在控制台执行go run myprog.go时,Go会在我的C驱动器上的某个随机位置构建一个新的可执行文件。

有没有办法配置它,使其始终将文件构建到特定位置,并且最好也避免名称的随机性?(即,始终构建到D:\Temp\LastBuild.exe)。

我找到了一些信息,但在执行go help rungo 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。它适用于快速测试代码片段,代码行数不超过一个屏幕的大小。

工作方法如下:

  1. 编辑代码。
  2. 运行go build
  3. 运行可执行文件,它将具有可预测的名称。
  4. 转到步骤(1)。

如果您与实现同时编写测试(应该这样做),则步骤如下:

  1. 编辑代码。
  2. 编辑测试套件。
  3. 运行go test
  4. 转到步骤(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

  1. Edit the code.
  2. go build it.
  3. Run your executable which will have predictable name.
  4. Go to step (1).

If you write tests in parallel with the implementation (and you should), this changes to

  1. Edit the code.
  2. Edit the test suite.
  3. go test it.
  4. Go to step (1).

Please see this recent thread on the mailing list for more insight on the same subject.

huangapple
  • 本文由 发表于 2014年10月9日 00:53:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/26262305.html
匿名

发表评论

匿名网友

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

确定