Avatar ·

Function declared in another file, but Go says "undefined": what to do?

Hi everyone! I just started learning Go and encountered a strange problem. I have a simple project with two files in the same folder:\n\n**main.go:**\n```go\npackage main\n\nimport "fmt"\n\nfunc main() {\n result := add(5, 3)\n fmt.Println("Result:", result)\n}\n```\n\n**math.go:**\n```go\npackage main\n\nfunc add(a int, b int) int {\n return a + b\n}\n```\n\nI run `go run main.go` and get an error:\n```\n# command-line-arguments\n.\\main.go:6:14: undefined: add\n```\n\nWhy doesn't Go see the `add` function declared in another file? Both files are in the same folder and have the same package main. I read that in Go you don't need to explicitly import functions from files in the same package. What could be the problem? I've already double-checked the syntax — everything seems correct. Please advise.