简单的c ++程序不运行

时间:2017-12-02 12:46:13

标签: c++ codeblocks

在Code :: Blocks中进行编程时,它不能为C ++编译。即使是这种简单的程序。

#include <iostream>
 using namespace std;
 int main()
 {
   cout << "Hello world!" << endl;
   return 0;
 }

它会给出这些错误。

=== Build: Debug in start (compiler: GNU GCC Compiler) ===

obj\Debug\start.o||In function `main':
C:\Users\dp\Desktop\c++\start\start.cpp|4|multiple definition of `main'
obj\Debug\main.o:C:\Users\dp\Desktop\c++\start\main.cpp|6|first defined here
error: ld returned 1 exit status
=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 6 second(s)) ===

我该怎么做才能解决这个问题。

1 个答案:

答案 0 :(得分:2)

As-is代码本身应该编译好。但是,因为错误表明您在多个源文件中有多个int main()函数定义。一个位于 start.cpp 中,另一个位于 main.cpp 文件中。要么只保留一个main()入口点,要么编译单个文件。使用g++前端进行编译,而不是使用gcc进行编译。

相关问题