2
root@kali:~/subfinder# go build
main.go:15:2: cannot find package 
"github.com/subfinder/subfinder/libsubfinder/helper" in any of:
    /usr/lib/go-1.11/src/github.com/subfinder/subfinder/libsubfinder/helper 
(from $GOROOT)
    /root/go
/src/github.com/subfinder/subfinder/libsubfinder/helper (from $GOPATH)
main.go:16:2: cannot find package "github.com/subfinder/subfinder/subf" in 
any of:
    /usr/lib/go-1.11/src/github.com/subfinder/subfinder/subf (from $GOROOT)
    /root/go
/src/github.com/subfinder/subfinder/subf (from $GOPATH)

Here is my go path version:

root@kali:~# go version
go version go1.11.4 linux/386

My Go ENV:

root@kali:~# go env
GOARCH="386"
GOBIN="/root/go_projects/bin"
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go
"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.11"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.11/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="387"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix- 
map=/tmp/go- 
build284184378=/tmp/go-build -gno-record-gcc-switches"

My .profile

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
      if [ -f ~/.bashrc ]; then
    . ~/.bashrc
 fi
 fi

 mesg n || true

export PATH=$PATH:/usr/local/go/bin
export GOPATH="$HOME/go_projects"
export GOBIN="$GOPATH/bin"
2

Golang is quite opinionated regarding which directories your source must be in. (And yet, it often doesn't give you a helpful or actionable error message about that.)

In any case, if your package is named github.com/subfinder/subfinder, then in order to build it you need to have the sources for it stored under $GOPATH/src/github.com/subfinder/subfinder, which in your case would be /root/go/src/github.com/subfinder/subfinder (from the environment listing, not the .profile.)

One way to ensure it will be checked out in the right location is to use go get to fetch it (and optionally build/install it.) Using go get with the -d option will simply download the sources, so you can modify them and build them if you need to do that in a separate step.

$ go get -d github.com/subfinder/subfinder

This command will fetch it into the first directory in your $GOPATH (which can actually be a list of directories separated by :, similar to how $PATH works, in the unlikely case you want to search multiple base directories for the packages.)


In your post, there's also a disconnect between the environment listing (which says GOPATH="/root/go") and the .profile (which says GOPATH="$HOME/go_projects".) I imagine that's because you're listing the .profile of a non-root user, while you're running the go build and listing the environment as root? Or maybe you have another issue causing your .profile not to be read, for instance not a login shell, or you have another profile file such as .bash_profile which takes precedence, etc.

It seems you also have an issue with a trailing newline in the $GOPATH setting of root (you can see the double quote only closes on the second line), which might be causing some of these problems... So to be sure you should probably try to fix that as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.