views:

156

answers:

2

i use the netbeans with MinGW and MYSY make /debugger but when i compile a basic cpp code in it and run it it produces two erorrs

this is the code runned and the output![alt text][1] box

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

output is

/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)

how can i solve this ?

+1  A: 

You have two different files in your project that define main(). One is called newfile.cpp, the other one is called newmain.c

And as the earlier comment notes, you will need to specify std::cout and std::endl

jwismar
+5  A: 

I can see three things here, the first two have been pointed out by Xavier and jwismar, but to consolidate:

  1. Both D:/Users/Home/Documents/NetBeansProjects/newApp/newfile.cpp and D:/Users/Home/Documents/NetBeansProjects/newApp/main.cpp define a main(). You'll need to remove one of these from your project.

  2. You'll need to be using std::cout and using std::endl.

  3. main() should always return an int.

Johnsyweb
Two should be "using std::endl;" Otherwise, excellent answer.
George
Thanks. Typo corrected.
Johnsyweb