Is main.cpp required?
Solution 1
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().
Solution 2
Name of the source file has nothing to do for a program successful build. All you need a source file that has main function. How ever, naming the file as main.cpp
is just a programming practice to just easily locate where the main function is.
Solution 3
No the main method doesn't have to be in a file called main.cpp
.
zeboidlund
Updated on July 18, 2022Comments
-
zeboidlund almost 2 years
I was trying to compile a program with
cmake
, and I ended up deleting mymain.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 amain.cpp
not found error, and wasn't sure whether or not inC++
a file known asmain.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.-
Benjamin Lindley over 12 yearsWhat does your
CMakeLists.txt
file look like? Does it specifically mentionmain.cpp
?
-