Search code examples
c++compiler-errorscodelite

I am getting a error in codelite when I am trying to run any cpp file other than main.cpp in my codelite project


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====

Solution

  • 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.