-1

I am making different files but the directories of storing the files is same. I am getting an error main redeclared in this block previous declaration at .\hello.go:5:6

How this can be resolved. Do I need to change the name of the main method. Can't I use it within the same directory?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
GeekyBoy
  • 15
  • 6

1 Answers1

2

From The Go Programming Language Specification:

A complete program is created by linking a single, unimported package called the main package with all the packages it imports, transitively. The main package must have package name main and declare a function main that takes no arguments and returns no value.

So if you want multiple main functions you need multiple programs, each defining their own main package.

If you want to keep all your code in the same package, do not call your functions main, give them different names.

Clément
  • 804
  • 6
  • 16