Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is go build doing nothing?

Tags:

go

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.

In folder A, if I say go build -v, I get a list of the stuff it's building.

In folder B, if I say go build -v, I get an immediate return with no 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 version returns 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. In the folder A, go install produces a .a file in the appropriate place under $GOPATH/pkg. In folder B, go install does not. 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. 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.

like image 826
Mason Wheeler Avatar asked Feb 02 '18 21:02

Mason Wheeler


People also ask

How do I run a go file after build?

The same way you'd run any other executable. ./program or program.exe . After you run go build main.go , there will be a new file with the name of the folder containing your main.go file. That is the executable. If the directory containing the main.go file is named toto , on unix you have to type ./toto to execute it.

Where does go build output go?

go build builds the command and leaves the result in the current working directory. go install builds the command in a temporary directory then moves it to $GOPATH/bin .

What is Gobuild?

gobuild is an automatic build tool that aims to replace Makefiles for simple projects written in the Go programming language. It creates a dependency graph of all local imports and compiles them in the right order using the gc Go compiler.

What happens go build?

go build command is generally used to compile the packages and dependencies that you have defined/used in your project. So how go build is executing internally, what compiler executes, which directories created or deleted; Those all questions are answered by go build command flags.


2 Answers

You mention that the temporary directories are gone after the build terminates.

You can retain these directories with the -work flag.

From 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.

like image 103
jlucktay Avatar answered Oct 08 '22 04:10

jlucktay


I also faced a similar issue, don't know the root cause but run

go build main.go

Basically, add the filename and try.

like image 1
Piyush Sinha Avatar answered Oct 08 '22 02:10

Piyush Sinha