Go: can't load package: package cmd/hello: cannot find package "."

Created on 24 Oct 2017  路  2Comments  路  Source: golang/go

What version of Go are you using (go version)?

go version go1.9 darwin/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/csj/git/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h8/glg18vq91h3b5x5nfpqnbcmw0000gn/T/go-build804657928=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I just do these:

  • Make diretory $GOPATH/src/cmd/hello
  • Make file $GOPATH/src/cmd/hello/main.go the content in the file:
package main

import (
    "fmt"
)

func main() {
    fmt.Println("hello world")
}

  • cd $GOPATH
  • go build cmd/hello

What did you expect to see?

to be build successfully.

What did you see instead?

can't load package: package cmd/hello: cannot find package "." in:
    /usr/local/Cellar/go/1.9/libexec/src/cmd/hello

What make you confused?

https://github.com/golang/go/blob/release-branch.go1.9/src/cmd/go/internal/load/pkg.go#L1735
why treat packages start with cmd/ && !contains '/' followed as "." ?

FrozenDueToAge

Most helpful comment

For better or for worse, this is documented at https://golang.org/cmd/go/#hdr-Description_of_package_lists: "Import paths beginning with "cmd/" only match source code in the Go repository."

All 2 comments

For better or for worse, this is documented at https://golang.org/cmd/go/#hdr-Description_of_package_lists: "Import paths beginning with "cmd/" only match source code in the Go repository."

Since this is a question which has been answered, I'll assume it's safe to now close this issue.

Was this page helpful?
0 / 5 - 0 ratings