go env key data are as follows
GOPATH="/home/zzy/goProject" GOROOT="/usr/local/go"
The project directory is like this
goProject ├── bin ├── pkg └── src └── go_learn └── day01 ├── hello │ ├── hello │ └── hello.go └── str_type ├── str.go └── world.go
hello.go my code is like this
package main import ( "fmt" "go_learn/day01/str_type/world" ## This sentence imports packages and keeps reporting errors ) func main() { fmt.Print("hello world") test() }
The
world.go code is like this
package main import "fmt" func test() { fmt.Print("LALALALA") }
go build reports an error like this
$ go build hello.go:5:2: cannot find package "go_learn/day01/str_type/world" in any of: /usr/local/go/src/go_learn/day01/str_type/world (from $GOROOT) /home/zzy/goProject/src/go_learn/day01/str_type/world (from $GOPATH)
finally solved! A very low problem. It is estimated that beginners will make
Just change the content of the world.go file
package world # It's a file, not a package, don't import main import "fmt" # The function name is capitalized so you can reference the function outside func Test() { fmt.Println("lll") }
Similar Posts:
- package wang/test is not in GOROOT (/usr/local/go/src/wang/test)
- $GOPATH not set [How to Solve]
- Intellij IDEA Golang Error: no Go files in D:\basic_tool\Go\src\gosvc
- Gopath not set in go command execution
- Go Project Start Error: package not in GOROOT & import cycle not allowed
- Go build Error: cannot find package “fmt” in any of [How to Solve]
- Python Standard Library: functools (cmp_to_key, lru_cache, total_ordering, partial, partialmethod, reduce, sing…
- Python uses decorator and reports error typeerror: ‘nonetype’ object is not callable ‘
- [Solved] Go Language Error: cannot find module providing package github.com/
- Xlua#: How to Call C