当我运行程序时,它会立即使IDE崩溃

  • 本文关键字:IDE 崩溃 运行 程序 c++
  • 更新时间 :
  • 英文 :


错误消息显示:

/tmp/something-148ec2.o: In function `main':
something.cpp:(.text+0x0): multiple definition of `main'
/tmp/main-c94e00.o:main.cpp:(.text+0x0): first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiler exit stat

这是代码:

#include<iostream>
using namespace std;
int main() {
int marks[] = { 25, 90, 98, 82, 60 };
int i = 0;
// while loop
while (true) {
cout<<marks[i]<<endl;
i++;
if (i == 4) {
break;
}
}
}                                         

我认为您正在使用CMake。如果是,则只能有一个包含main函数的文件。为了使用具有主函数的多个文件,您必须在CMake文件中注册C++可执行文件。

大多数IDE,如Netbeans、CLion、Eclipse(我认为(都有相同的行为。

我使用CLion,这个问题可以通过安装这个插件来解决

这个扩展名在CMake file中注册您的C++文件。

最新更新