Multiple definition of main()

前端 未结 5 1741
刺人心
刺人心 2021-01-24 06:36

Hi guys trying to use two main() and getting this error multiple definition of main(). I renamed my main functions then why is this error and also first defined here for my prin

5条回答
  •  萌比男神i
    2021-01-24 06:46

    Basically any C (or even C++) program is a bunch of functions calling each other.
    To begin a program execution, you have to pick one of these functions and call it first.
    By convention, this initial function is called main.

    When you include several source files in a project, the IDE compiles them all, then calls the linker which looks for one single function called main and generates an executable file that will call it.

    If, for any reason, you defined two "main" functions inside all these files, the linker will warn you that it cannot choose on its own which one you intended to be the starting point of your program.

提交回复
热议问题