This question already has an answer here:
- go build works fine but go run fails 2 answers
I have the following files:
gopackage/main.go
:
package main
func main () {
foo();
}
gopackage/otherfile.go
:
package main
import "fmt"
func foo() {
fmt.Print("foo
")
}
Apparently, the reference to foo
from main.go
does not resolve to the definition of foo
in otherfile.go
:
> go run main.go
# command-line-arguments
./main.go:4: undefined: foo
Why not? I have been told that all files in the same directory comprise a single package, which is a single scope.
</div>