[GO] The entry file under the main package in golang calls other go file functions and appears undefined

It is recommended that there is only one entry file for main.go under the golang main package

When there are other go files, and functions are defined in other go files

 

This function is called in the main.go entry file, go run main.go is executed, it will prompt undefined

If you have to do this, then all files must be added when go run, otherwise only the main.go file will be loaded by default

Only files in the non-main package will be automatically loaded through dependencies. So you need to enter multiple files as parameters

 

Should use go run a.go b.go c.go or go run *.go to run, compile the same


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *