是否需要main.cpp? [英] Is main.cpp required?
问题描述
我试图用 cmake
编译程序,最终删除了我的 main.cpp
文件,该文件刚刚复合到另一个文件中,文件名为的项目(即,我只是将主要功能剪切并粘贴到了那个项目中).问题是我遇到一个 main.cpp
找不到错误,并且不确定在 C ++
中是否存在一个称为 main.cpp 的文件.code>是必需的,还是我可以有一个包含不同标题的文件,但包含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?
修改我应该注意,我已经删除了对 main
的任何规范,并重新编译了该程序.
Edit
I should note that I have removed any specification to main
and have recompiled this program.
推荐答案
否,您不需要名为main.cpp的文件.除非您正在构建应用程序,否则不需要包含main()的文件.也就是说,如果您只是构建函数库或独立的目标文件,则不需要main().
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().
这篇关于是否需要main.cpp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!