简体   繁体   English

为什么 go build 什么都不做?

[英]Why is go build doing nothing?

I'm running into a bizarre problem at work.我在工作中遇到了一个奇怪的问题。

I have a project.我有一个项目。 In this project are two packages, each in its own folder.在这个项目中有两个包,每个包都在自己的文件夹中。 Each folder contains various .go files that are part of that package.每个文件夹都包含各种.go文件,这些文件是 package 的一部分。

In folder A, if I say go build -v , I get a list of the stuff it's building.在文件夹 A 中,如果我说go build -v ,我会得到它正在构建的东西的列表。

In folder B, if I say go build -v , I get an immediate return with no output.在文件夹 B 中,如果我说go build -v ,我会立即返回没有 output。

Both folders contain nothing but .go files, and there is no easily-identifiable reason why it is building the code in the one and building nothing in the other.这两个文件夹只包含.go文件,并且没有容易识别的原因为什么它在一个文件夹中构建代码而在另一个文件夹中不构建任何内容。

go version returns go version go1.7.5 linux/amd64 go version返回go version go1.7.5 linux/amd64

How in the world do I figure out what's going on here?我到底怎么弄清楚这里发生了什么?

EDIT : To clarify issues brought up in comments:编辑:澄清评论中提出的问题:

There is no package main in either folder.两个文件夹中都没有package main In the folder A, go install produces a .a file in the appropriate place under $GOPATH/pkg .在文件夹 A 中, go install$GOPATH/pkg下的适当位置生成一个.a文件。 In folder B, go install does not.在文件夹 B 中, go install没有。 It is doing nothing, and failing silently.它什么都不做,默默地失败。 Something is legitimately going wrong here.这里确实出了点问题。

Suggested remedies from comments include using the -a flag (errors out on something that appears to be completely unrelated) and using the -x flag.评论中建议的补救措施包括使用-a标志(在看似完全不相关的事情上出错)和使用-x标志。 The -x flag, which supposedly should give extremely verbose output, instead is useless, outputting single lines referring to temp files that do not exist once the build terminates, such as WORK=/tmp/go-build026498757 . -x标志本来应该给出极其冗长的 output,但实际上是无用的,它输出单行引用临时文件,这些临时文件在构建终止后不存在,例如WORK=/tmp/go-build026498757

You mention that the temporary directories are gone after the build terminates.您提到构建终止后临时目录消失了。

You can retain these directories with the -work flag.您可以使用-work标志保留这些目录。

From go help build :go help build

The build flags are shared by the build, clean, get, install, list, run, and test commands:

...

    -work
            print the name of the temporary work directory and
            do not delete it when exiting.

This should help provide some more information and context around what is and is not happening.这应该有助于提供有关正在发生和未发生的事情的更多信息和背景。

It's likely that you already have an up-to-date build installed in your gopath.您的 gopath 中可能已经安装了最新版本。 This might mean that you did something like ran go install on that particular package previously and have yet to modify any of the files in the directory.这可能意味着您之前在该特定软件包上执行了诸如运行go install操作,并且尚未修改目录中的任何文件。

Check Go's pkg directory for the corresponding *.a library and see if the modification timestamp on it is later than the timestamps on your source files.检查 Go 的pkg目录中是否有相应的*.a库,并查看其上的修改时间戳是否晚于源文件上的时间戳。

I think go build's result is hiding by your editor.(file tree)我认为 go build 的结果被你的编辑器隐藏了。(文件树)

In my case, I am using vscode.就我而言,我使用的是 vscode。
vscode hides files that first char is '.' vscode 隐藏第一个字符为 '.' 的文件
if you move to src directory and type ls -al in terminal如果你移动到 src 目录并在终端中输入ls -al

I also faced a similar issue, don't know the root cause but run我也遇到了类似的问题,不知道根本原因,但运行

go build main.go

Basically, add the filename and try.基本上,添加文件名并尝试。

Yep.是的。 By adding file name it works fine.通过添加文件名,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM