user769301
user769301

Reputation: 21

Cannot compile C++ code with Netbeans 7.0 on Mac OS

I am a new user to Netbeans and Mac OS both. I have a very simple C++ code

#include <iostream>
#include <string>

using namespace std;
int main()
{
    int i,count=0;
    char c;
    cin>>c;
    for (i=0;i<10;i++)
    {
           count=count+1;   

    }
    cout<<"count="<<count;      
}

I got the error below:

> "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/azadeh
mkdir -p dist/Debug/GNU-MacOSX
g++     -o dist/Debug/GNU-MacOSX/azadeh build/Debug/GNU-MacOSX/string.o build/Debug/GNU-MacOSX/string-number.o  
ld: duplicate symbol _main in build/Debug/GNU-MacOSX/string-number.o and build/Debug/GNU-MacOSX/string.o
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/azadeh] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

>BUILD FAILED (exit value 2, total time: 60ms)

Does have anybody any idea how to solve this?

Thanks. Ehsan

Upvotes: 2

Views: 920

Answers (1)

Cat Plus Plus
Cat Plus Plus

Reputation: 129944

You're linking two files together, and they both have main function defined. You need to remove one of those functions.

Upvotes: 4

Related Questions