GO:另一个文件(相同的程序包)中的对象引发未定义的错误

File: $GOPATH/src/scratch_go_code/main/main.go

package main

import "fmt"

func main() {
    fmt.Println("Hello World")
    cloud := Cloud{}
    cloud.Say()
}

file $GOPATH/src/scratch_go_code/main/cloud.go

package main

import "fmt"

type Cloud struct{}

func (Cloud) Say() {
    fmt.Println("I'm a cloud in the main package")
}

Running: go install scratch_go_code/... && go run main/main.go throws:

# command-line-arguments
main/main.go:7: undefined: Cloud

Any idea why?

This should work

go build scratch_go_code/main

You have to either use go build or pass both files to go run, example :

go run main/*.go

using go build :

cd scratch_go_code/ && go build && ./scratch_go_code