c++ - 在netbeans中编译cpp代码报错,如何解决?

标签 c++ netbeans mingw

我将 netbeans 与 MinGW 和 MYSY make/debugger 一起使用,但是当我在其中编译一个基本的 cpp 代码并运行它时,它会产生两个错误

这是运行的代码和输出![alt text][1] 框

#include <iostream>
void main()
{
  cout << "Hello World!" << endl;  
  cout << "Welcome to C++ Programming" << endl;
}

输出是

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/d/Users/Home/Documents/NetBeansProjects/newApp'
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/newapp.exe
make[2]: Entering directory `/d/Users/Home/Documents/NetBeansProjects/newApp'
mkdir -p dist/Debug/MinGW-Windows
g++.exe     -o dist/Debug/MinGW-Windows/newapp build/Debug/MinGW-Windows/newmain.o build/Debug/MinGW-Windows/newfile.o build/Debug/MinGW-Windows/main.o  
build/Debug/MinGW-Windows/newfile.o: In function `main':

D:/Users/Home/Documents/NetBeansProjects/newApp/newfile.cpp:5: multiple definition of `main'

build/Debug/MinGW-Windows/newmain.o:D:/Users/Home/Documents/NetBeansProjects/newApp/newmain.c:15: first defined here

build/Debug/MinGW-Windows/main.o: In function `main':

D:/Users/Home/Documents/NetBeansProjects/newApp/main.cpp:13: multiple definition of `main'

build/Debug/MinGW-Windows/newmain.o:D:/Users/Home/Documents/NetBeansProjects/newApp/newmain.c:15: first defined here

collect2: ld returned 1 exit status

make[2]: *** [dist/Debug/MinGW-Windows/newapp.exe] Error 1
make[2]: Leaving directory `/d/Users/Home/Documents/NetBeansProjects/newApp'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/d/Users/Home/Documents/NetBeansProjects/newApp'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

我该如何解决这个问题?

最佳答案

我可以在这里看到三件事,前两件事已由 Xavier 和 jwismar 指出,但要巩固:

  1. D:/Users/Home/Documents/NetBeansProjects/newApp/newfile.cppD:/Users/Home/Documents/NetBeansProjects/newApp/main.cpp 定义一个 main()。您需要从您的项目中删除其中一个。

  2. 您需要使用 std::cout使用 std::endl

  3. main() 应该总是返回一个 int

关于c++ - 在netbeans中编译cpp代码报错,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2909991/

相关文章:

c - 在 Windows 上使用 MinGW 调用 GCC 时如何将 Win32 指定为输出

c++ - 需要帮助从我的数组中排除某些东西

c++ - 函数指针问题

c++ - 使用模板参数实例化模板类

c++ - 在 C++ 中合并两个 boost 侵入集?

Netbeans 运行我的所有项目

java - 什么是 ${project.licensePath}?

c++ - mingw g++ 看不到 sdl-config

gdb - 如何在使用 mingw gdb 调试时向程序提供输入

netbeans - Netbeans 创建 Glassfish 域的管理员用户和密码?