简体   繁体   中英

go build mistakes .go/src for go/src in looking for dependencies

I'm trying to install a package from github . The reported errors show that go build looks for source files in /go/src rather than .go/src (= $GOPATH ). Look for /home/er/go/src/ in the error messages. How can I troubleshoot this problem?

~/.go/src/netbackup $ echo $GOPATH
/home/er/.go
~/.go/src/netbackup $ go version
go version go1.10.4 linux/amd64
~/.go/src/netbackup $ sudo go build
main.go:17:2: cannot find package "github.com/marcopaganini/logger" in any of:
/usr/lib/go-1.10/src/github.com/marcopaganini/logger (from $GOROOT)
/home/er/go/src/github.com/marcopaganini/logger (from $GOPATH)
main.go:18:2: cannot find package "github.com/marcopaganini/netbackup/config" in any of:
/usr/lib/go-1.10/src/github.com/marcopaganini/netbackup/config (from $GOROOT)
/home/er/go/src/github.com/marcopaganini/netbackup/config (from $GOPATH)
main.go:19:2: cannot find package "github.com/marcopaganini/netbackup/execute" in any of:
/usr/lib/go-1.10/src/github.com/marcopaganini/netbackup/execute (from $GOROOT)
/home/er/go/src/github.com/marcopaganini/netbackup/execute (from $GOPATH)
main.go:20:2: cannot find package "github.com/marcopaganini/netbackup/transports" in any of:
/usr/lib/go-1.10/src/github.com/marcopaganini/netbackup/transports (from $GOROOT)
/home/er/go/src/github.com/marcopaganini/netbackup/transports (from $GOPATH)

~/.go/src/netbackup $ tree
.
├── config
│   ├── config.go
│   └── config_test.go
├── examples
│   └── restic-example.conf
├── execute
│   └── execute.go
├── flags.go
├── LICENSE
├── main.go
├── main_test.go
├── README.md
└── transports
    ├── rclone.go
    ├── rclone_test.go
    ├── rdiff_backup.go
    ├── rdiff_backup_test.go
    ├── restic.go
    ├── restic_test.go
    ├── rsync.go
    ├── rsync_test.go
    ├── transports.go
    └── transports_test.go

4 directories, 19 files

~/.go/src/logger $ tree
.
├── LICENSE
├── logger.go
└── README.md

0 directories, 3 files

There are a couple of issues in the list above.

First, the project is not cloned in the right path. According to the error message, the compiler searches for it under $GOPATH/src/github.com/marcopaganini/netbackup but the project is directly cloned in $GOPATH/src/ .

The second one is that the IDE, if I infer correctly from the question tag here as GoLand, did not automatically configured itself to the GOPATH that you have, $HOME/.go but rather it's configured to $HOME/go .

If your GOPATH really is $HOME/.go , then you should go under the IDE settings at Settings/Preferences | Go | GOPATH Settings/Preferences | Go | GOPATH Settings/Preferences | Go | GOPATH and set the Global GOPATH value to be the one you need.

However, if $HOME/.go is where Go itself is installed, or you don't have any setting for GOPATH in your shell, which you can check using go env GOPATH , then you should clone the project under the path that the error tells you about, or simply run go get github.com/marcopaganini/netbackup/...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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