I have a problem (on windows and now on ubuntu, too). I have some libraries from github (among others cobra) and installed them via
go get ...
When I now want to build or run my application I get this message:
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: open /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: no such file or directory
/usr/local/go is the GOROOT
Which is absolutely correct since it is not there but under my GOPATH. I looked around now for a while but cannot solve that problem - Means, I solved the problem with copying the packages manually to GOROOT but this is not a real solution, I guess.
Is that the full output you got from go get -v -x github.com/spf13/cobra/cobra? We can’t see how the compiling does not work without seeing what happened.
Go-getting does compilation as part of it’s job. If go-get works, compilation works. But you’re not showing us any errors with your current setup, so it’s hard to say more.
Is your GOPATH not /home/marczahn/go? Your previous output of go env had GOPATH="/home/.../go/" I had hoped you were trying to hide your username and replaced it with .... Also, with g1.8 GOPATH defaults to $HOME/go, which seems to be what you are doing, so there is no need to actually set it.
What do you mean by “Go does not try to load them from GOPATH”? The go get output you provided seems to be using a GOPATH, putting binaries in $GOPATH/bin and compiled packages in $GOPATH/pkg like I expect.
Yeah - Tried to hide my username - Fail And even not worth it…
Go seems to not use GOPATH when I want to compile my application (go build main.go) - Otherwise I would not have this error:
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: open /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: no such file or directory
correct?
This works:
go build -pkgdir /home/marczahn/go/pkg/ -o main main.go
What version of go are you using? How did you install it?
My attempts at replicating this problem have failed. I get more useful error messages like:
âžś ~ go build -v -o main main.go
main.go:5:2: cannot find package "github.com/pkg/errors" in any of:
/usr/local/go/src/github.com/pkg/errors (from $GOROOT)
/home/alaster/go/src/github.com/pkg/errors (from $GOPATH)
âžś ~ file /home/alaster/go
/home/alaster/go: cannot open `/home/alaster/go' (No such file or directory)
Notice that this tries to use the default GOPATH, which does not exist on that system.
Could you post a main.go that this problem occurs with and the path where you keep it?
Indeed - do not use go build somefile.go. Many things will be different and confusing when you are giving it a single file. Use go build on packages, for example the package you are standing in when running the command:
@nathankerr
Go 1.8; I installed it as described on the official website -> Downloading, Moving to usr/local, setting up go path and create GOPATH-variable
08:33 $ go build -v -o main main.go
_/home/marczahn/go/src/engine_backoffice/resources/views
_/home/marczahn/go/src/engine_backoffice/models/auth
_/home/marczahn/go/src/engine_backoffice/models
_/home/marczahn/go/src/engine_backoffice/config
_/home/marczahn/go/src/engine_backoffice/web
_/home/marczahn/go/src/engine_backoffice/cmd
_/home/marczahn/go/src/engine_backoffice/application
command-line-arguments
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: open /usr/local/go/pkg/linux_amd64/github.com/spf13/cobra.a: no such file or directory
Sorry to be saying so much “do not” here, but you seem to have found a perfect storm of practices that are shunned or just not recommended when developing Go.