This question already has an answer here:
this is my file tree:
.
├── float.go
└── main.go
main.go:
package main
func main(){
Float()
}
float.go:
package main
import "fmt"
func Float(){
fmt.Println( "hello world")
}
when I try to compile the main.go, it throws an error
command-line-arguments ./main.go:4:2: undefined: Float
Why can't I use the function defined in another file of same packages?
</div>
As package main
is split into multiple files, you have to pass all the files to the go compiler when building.
Either you could list it one by one like
go run main.go float.go
or you could
go run *.go