Golang 1.10 is installed in D: \ Program Files \ Go

GOROOT D: \ Program Files \ Go

GOPATH D: \ Program Files \ Go \ Projects

The test project is located in D: \ Program Files \ Go \ Projects \ src \ tmp

Main.go code:

package main import "fmt" func main() { fmt.Println("tmp1") tmp() } 

The tmp.go file is in the same directory as main.go:

 package main import "fmt" func tmp() { fmt.Println("tmp2") } 

When I run the go run main.go command, I get the error:

command-line-arguments

. \ main.go: 7: 2: undefined: tmp

Why does not the tmp () function call work? After all, main.go and tmp.go are in the same directory and package. And go build works without problems.

    1 answer 1

    For the go run, you should transfer all the files in the main package, separated by a space:

     go run main.go tmp.go 

    Ideologically, go run is designed to quickly launch small programs from one file, in all other cases use go build / install.