2010-05-26 75 views
0

我使用與MinGW和MYSY化妝/調試器,但在NetBeans當我編譯中有一個基本的cpp代碼,並運行它,它產生兩個erorrs在netbeans中編譯cpp代碼會產生錯誤,該如何解決?

這拼命地跑的代碼,並輸出![ALT文本] [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) 

我怎樣才能解決這個問題?

+1

你有沒有至少嘗試'使用std :: cout;使用std :: endl;'? – 2010-05-26 03:45:45

回答

5

我可以在這裏看到三件事情,前兩個已指出,由Xavier和jwismar,但鞏固:

  1. 兩個D:/Users/Home/Documents/NetBeansProjects/newApp/newfile.cppD:/Users/Home/Documents/NetBeansProjects/newApp/main.cpp定義main()。你需要從你的項目中刪除其中的一個。

  2. 您需要是using std::coutusing std::endl

  3. main()應該總是返回一個int

+1

兩個應該是「使用std :: endl;」否則,很好的答案。 – George 2010-05-26 04:50:30

+0

謝謝。錯字更正。 – Johnsyweb 2010-05-26 05:00:13

1

您的項目中有兩個不同的文件定義main()。一個叫newfile.cpp,另外一個被稱爲newmain.c

而作爲先前的評論指出,您將需要指定std::coutstd::endl