Is main.cpp required?

荒凉一梦 提交于 2021-02-07 05:51:59

问题


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.


回答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().




回答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.




回答3:


No the main method doesn't have to be in a file called main.cpp.




回答4:


You can use any file name you want, you just need to update it in the makefile



来源:https://stackoverflow.com/questions/8628426/is-main-cpp-required

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!