Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ 2010 - fatal error LNK1169: one or more multiply defined symbols found

this is a program :

#include <iostream>
using namespace std;

int main() {
cout << "Enter a number";
int i;
cin >> i;
try {
    if( i == 0 ) throw 0;
    if( i == 2 ) throw "error";
} catch( int i ) {
    cout << "can't divide by 0";
 }
   catch( ... ) {
       cout << "catching other exceptions";
   }
}

On compiling (Microsoft visual C++ 2010 express on Windows 7), I get the error which says:

fatal error LNK1169: one or more multiply defined symbols found

like image 299
Suhail Gupta Avatar asked Jun 28 '11 12:06

Suhail Gupta


2 Answers

Actually there is no error in this code.

Number of source files could be the problem. Try this code as a new project in the same compiler or try deleting the files from the source files option in the left side of Text Area (i.e where you are writing your code)

This should compile then.

like image 145
saplingPro Avatar answered Sep 18 '22 04:09

saplingPro


Finally I think that I found the most plausible explanation for the problem as you know we usually assign main as an integer (int main) in our .cpp file and sometimes we may write more than one .cpp file in the same project with the same (int main () ).so for the program that means we have accidentally repeated the same function twice in the same project folder .What we have to do is this just write one .cpp file with (int main) while the other .cpp files in the same project write them with (int submain) and see what gona happen.

like image 25
saqrthabet Avatar answered Sep 19 '22 04:09

saqrthabet