# command-line-arguments ./main.go:16:14: undefined: Load Compilation finished with exit code 2

During the development of the go project, the following problems occurred.

Error problem:

Idea running error:
insert image description here
After go bulild,
go run main.go starts and the error message is as follows:

# command-line-arguments

./main.go:16:14: undefined: Load

Compilation finished with exit code 2

Running the binary, it succeeds:
insert image description here

analyze:

insert image description here
In my project, there is a config.go at the same level as main. When go runs, there is a problem of go loading multiple files, so all .go files need to be included in the parameters, that is

go run *.go

This will also work, but it's not optimal.

the best solution:

The outermost layer only puts the main.go that starts, and creates a new directory for storing other .go files:
insert image description here
in this way, the startup is successful.

Guess you like

Origin blog.csdn.net/quanqxj/article/details/100553694