Avatar ·

Function declared in another file is not visible — "undefined" error in Go

Hi everyone! I just started learning Go and encountered a very strange problem. I have two files in the same `main` folder: **main.go:** ```go package main func main() { hello() } ``` **helper.go:** ```go package main func hello() { println("Hello from helper!") } ``` I run the program with `go run main.go` and get the error: ``` # command-line-arguments ./main.go:4:2: undefined: hello ``` Why does this happen? Both functions are in the same `main` package, and in other languages (e.g., Python or Java), files in the same folder usually "see" each other automatically. I tried renaming files and checking syntax — all to no avail. Please tell me, what am I doing wrong? How to properly organize code in Go so that functions from different files are accessible? <<>>

Why the "undefined" error occurs

The problem is that the command go run main.go runs only one file — ma