This warning/problem pops up in VS code;
main redeclared in this block compiler(DuplicateDecl) <my another Go file name in my directory> other declaration of main
I am have all my Go practice files in one directory and each file has a func main() block.
Is anyone familiar with the warning? if so how may I resolve.
But, Even though I get this error.. or what ever you call it..
I can still run my Go code in the terminal and see my input/output without any error.
Separating them into their own directories is the only solution.
In Go, a directory is a package, and a package can only have one function with a given name (with the exception of init(), which is a special case). You think of all your .go files in a directory as separate, but Go does not; it sees a single package, and that package declares multiple functions called main, which is not permitted.
At the end of the day, I resolved this problem by creating a directory for each Go file.
I know it is not a perfect solution for this problem..
If some one knows some thing please share with us.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With