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.
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.
Files with CPP file extension are source code files for applications written in C++ programming language.
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.
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With