How to fix the error: multiple definition of `main’
Overview
In this post, we will fix the error multiple definition of `main’ in C++ project. The error occurs if the C++ project has multiples main functions defined in the project.
Error
Sample error log:
Documents/CProjects/TestingDocsProject/syntax.cpp:10: multiple definition of `main’
obj\Debug\main.o:/Documents/CProjects/TestingDocsProject/main.cpp:10: first defined here
In this example, the source code files syntax.cpp and main.cpp contains the main() routine defined.
Error Fix
The main function is the entry point for the C++ program execution.
The fix for the error is to scan the source files listed in the build log and remove the unwanted main routines in the respective files. We can have one definition of the main function for the project to run.
Alternatively, we can also remove source code files from the project which has multiple definitions of the main routine.
That’s it. This will resolve the error in the project.