Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go install doesn't create any bin file

Tags:

go

My folder structure is correct, i can both run go install from inside the package folder and from anywhere in the system, adding the package (folder) name after install.

For example, my workspace is the following:

Go\   bin\   pkg\   src\     name\       file.go 

then, if i run

cd %GOPATH%\src\name go install 

or

go install name 

no errors are generated and my workspace becomes the following

Go\   bin\   pkg\     windows_amd64\ <-- new!       name.a       <-- new!   src\     name\       file.go 

Package files are correctly created, but bin files aren't.

My go env is the following:

C:\Users\...>go env set GOARCH=amd64 set GOBIN=C:\Users\myname\Documents\Go\bin set GOCHAR=6 set GOEXE=.exe set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\Users\myname\Documents\Go set GORACE= set GOROOT=C:\Go set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set CC=gcc set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 set CXX=g++ set CGO_ENABLED=1 

Why is this the case? Am i missing something, doing something wrong? I want bin files to be created along with package files.

like image 429
castan Avatar asked Nov 01 '14 23:11

castan


People also ask

Where does go install put the binary?

Much like the previous behaviour of go get , go install places binaries in $GOPATH/bin , or in $GOBIN if set. See the “Setting up your PATH “ section in Installing Go to ensure your PATH is set correctly.

How do I install go files?

Add the Go install directory to your system's shell path. That way, you'll be able to run your program's executable without specifying where the executable is. Once you've updated the shell path, run the go install command to compile and install the package. Run your application by simply typing its name.

Where is go installed by default?

Download the latest Go package ( . pkg ) file from Go's official downloads page. Open the package and follow the on-screen instructions to install Go. By default, Go will be installed in /usr/local/go .

Should I use go get or go install?

go install , with or without a version suffix (as described above), is now the recommended way to build and install packages in module mode. go get should be used with the -d flag to adjust the current module's dependencies without building packages, and use of go get to build and install packages is deprecated.


1 Answers

One reason could be the file.go isn't in package main.
See for instance "Your first program"

If it was, that would generate a executable in bin.

The article "How does the go build command work ?" does mention:

A Go command is a package who’s name is main.
Main packages, or commands, are compiled just like other packages, but then undergo several additional steps to be linked into final executable.

like image 147
VonC Avatar answered Sep 20 '22 06:09

VonC