This question already has an answer here:
In $GOPATH/src/testapp
I have two files
main.go
otherfile.go
main.go has
package main
import "fmt"
func main() {
fmt.Println(SomeFunc())
}
otherfile.go has
package main
func SomeFunc() string {
return "a thing"
}
When I try to run with go run main.go
, I get an error
./main.go:6: undefined: SomeFunc
I thought I could create another file with package main
and code in main.go
would have access to its declarations. Why doesn't this work? How would I do something like this?
</div>
If I run go run *.go
it works.
It also works if I go build
and then ./testapp
.
Hopefully this question helps someone in the future.
Some comments on this page helped me: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/555