Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is main.cpp required?

Tags:

c++

syntax

main

I was trying to compile a program with cmake, and I ended up deleting my main.cpp file, which I had just compounded into another file which held the name of my project (i.e., I just cut and pasted the main function into that one). The problem is that I got a main.cpp not found error, and wasn't sure whether or not in C++ a file known as main.cpp is required, or can I have a file with a different title which contains the function main instead?

Edit I should note that I have removed any specification to main and have recompiled this program.

like image 628
zeboidlund Avatar asked Dec 25 '11 05:12

zeboidlund


People also ask

What is the purpose of main CPP?

main() Function in C++ main() function is the entry point of any C++ program. It is the point at which execution of program is started.

Is Main CPP a source file?

Files with CPP file extension are source code files for applications written in C++ programming language.

Is int main necessary?

The short answer, is because the C++ standard requires main() to return int . As you probably know, the return value from the main() function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished.


1 Answers

No, you don't need a file named main.cpp. You don't need a file containing main() unless you are building an application. That is, if you were just building a library of functions or a standalone object file you would not require main().

like image 95
Duck Avatar answered Oct 19 '22 13:10

Duck