-1

When I create a project in codelite IDE[13.0.8], the main.cpp in the src folder of that project runs fine. But following error arises when I create a new cpp file within the same project

my project name is qrec1 and the new file I tried to build within the same project is main2.cpp(with one more main function)

C:/Users/AT/Documents/Workspace1/qrec1/main.cpp:4: multiple definition of `main'; Debug/main2.cpp.o:C:/Users/AT/Documents/Workspace1/qrec1/main2.cpp:3: first defined here
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====
anonymous38653
  • 393
  • 4
  • 16
  • 3
    The important part of the error message is this: "multiple definition of 'main'". How many `main` functions do you have in your program? – Some programmer dude Apr 07 '20 at 11:10
  • @Someprogrammerdude alright, now I've understood the concept But when I try to run any other file in the project , the main.cpp is just the one that runs. What should I do to run any other file else than main.cpp in my project – anonymous38653 Apr 07 '20 at 11:41
  • 1
    What do you mean by "run a file"? It's not Python, you don't run a file. You compile .`cpp` files, link them into a single program and run it. Execution of a program starts from `int main()` function, that's why it must be present and there must be exactly one per program. – Yksisarvinen Apr 07 '20 at 12:06
  • @Yksisarvinen Thanks for your comment, now I've understood. I was completely missing the point which you so correctly explained – anonymous38653 Apr 07 '20 at 12:33

1 Answers1

0

You cannot have two main functions in the same project. Put them in separate projects or rename one of the functions and call it from the other main function. You can never have more than one main() function in your project since it is the entrypoint.

walid barakat
  • 455
  • 1
  • 6
  • 17