Click here to Skip to main content
15,891,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: :rose: Check for validity of IP address Pin
CPallini25-Mar-10 2:52
mveCPallini25-Mar-10 2:52 
AnswerRe: Check for validity of IP address Pin
krish_kumar25-Mar-10 2:55
krish_kumar25-Mar-10 2:55 
JokeRe: Check for validity of IP address Pin
enhzflep25-Mar-10 3:08
enhzflep25-Mar-10 3:08 
GeneralRe: Check for validity of IP address Pin
David Crow25-Mar-10 3:20
David Crow25-Mar-10 3:20 
GeneralRe: Check for validity of IP address Pin
CPallini25-Mar-10 3:48
mveCPallini25-Mar-10 3:48 
QuestionTools for reverse engineering Pin
tom groezer25-Mar-10 0:58
tom groezer25-Mar-10 0:58 
AnswerRe: Tools for reverse engineering Pin
enhzflep25-Mar-10 3:07
enhzflep25-Mar-10 3:07 
Questionerror LNK2005...already defined in .... Pin
rupeshkp72825-Mar-10 0:26
rupeshkp72825-Mar-10 0:26 
error LNK2005...already defined

While building my code in VS2008 I am getting a build error: error LNK2005...already defined in ....
1>Linking...
1>Main.obj : error LNK2005: "unsigned char * X1" (?X1@@3PAEA) already defined in BC.obj
1>Main.obj : error LNK2005: "char * X2" (?X2@@3PADA) already defined in BC.obj
1>Rs.obj : error LNK2005: "unsigned char * X1" (?X1@@3PAEA) already defined in BC.obj
1>Rs.obj : error LNK2005: "char * X2" (?X2@@3PADA) already defined in BC.obj

In my project I have three .h files:
1) Common_Definitions.h
unsigned char X1[16];
char X2[4];

struct xyz
{
UINT32 X3;
unsigned int X4[4];
long X5;
int X6;
int X7;
};


2) BC.h
3) RS.h

I have three .cpp files
1) Main.cpp
2) BC.cpp
3) RS.cpp


In Common_Definitions.h I have definitions/declarations which I want to be available in entire project, While BC.h and RS.h has corncenred variables.
I have included Common_Definitions.h in BC.h and RS.h.
#ifndef Common_Definitions_h
#define Common_Definitions_h
#include "Common_Definitions.h"
#endif

I have included BC.h and RS.h in their corresponding .cpp files.
I have included BC.h and RS.h also in Main.cpp

Now while building I get the linker error LNK2005.
How to resolve it?


Earlier when I had included Common_Definitions.h in BC.h and RS.h directly without ifndef.
#include "Common_Definitions.h"
then it was giving compilation error:
1>d:\...\common_deFINITIONS.h(18) : error C2086: 'unsigned char X1[16]' : redefinition
1> d:\...\common_deFINITIONS.h(18) : see declaration of 'X1'
1>d:\...\common_deFINITIONS.h(19) : error C2086: 'char X2[4]' : redefinition
1> d:\...\common_deFINITIONS.h(19) : see declaration of 'X2'
1>dd:\...\common_deFINITIONS.h(22) : error C2011: 'XYZ' : 'struct' type redefinition
1> d:\...\common_deFINITIONS.h(22) : see declaration of 'XYZ'

So to resolve that I have included Common_Definitions.h in BC.h and RS.h using ifndef.
#ifndef Common_Definitions_h
#define Common_Definitions_h
#include "Common_Definitions.h"
#endif
But this is leading to linker error.


Please let me know how to resolve this compiler and linker issue?
AnswerRe: error LNK2005...already defined in .... Pin
Eugen Podsypalnikov25-Mar-10 0:53
Eugen Podsypalnikov25-Mar-10 0:53 
GeneralRe: error LNK2005...already defined in .... Pin
rupeshkp72825-Mar-10 1:07
rupeshkp72825-Mar-10 1:07 
GeneralRe: error LNK2005...already defined in .... Pin
Eugen Podsypalnikov25-Mar-10 1:17
Eugen Podsypalnikov25-Mar-10 1:17 
GeneralRe: error LNK2005...already defined in .... Pin
rupeshkp72825-Mar-10 1:33
rupeshkp72825-Mar-10 1:33 
GeneralRe: error LNK2005...already defined in .... Pin
Eugen Podsypalnikov25-Mar-10 2:12
Eugen Podsypalnikov25-Mar-10 2:12 
GeneralRe: error LNK2005...already defined in .... Pin
rupeshkp72825-Mar-10 2:21
rupeshkp72825-Mar-10 2:21 
QuestionConnection with mysql an Crecordset Pin
Shivanand Gupta24-Mar-10 23:47
Shivanand Gupta24-Mar-10 23:47 
AnswerRe: Connection with mysql an Crecordset Pin
CPallini25-Mar-10 0:14
mveCPallini25-Mar-10 0:14 
GeneralRe: Connection with mysql an Crecordset Pin
Shivanand Gupta25-Mar-10 20:48
Shivanand Gupta25-Mar-10 20:48 
QuestionRe: Connection with mysql an Crecordset Pin
CPallini25-Mar-10 21:42
mveCPallini25-Mar-10 21:42 
QuestionData encryption Pin
Code-o-mat24-Mar-10 23:02
Code-o-mat24-Mar-10 23:02 
AnswerRe: Data encryption Pin
BIJU Manjeri24-Mar-10 23:26
BIJU Manjeri24-Mar-10 23:26 
GeneralRe: Data encryption Pin
Code-o-mat24-Mar-10 23:49
Code-o-mat24-Mar-10 23:49 
GeneralRe: Data encryption Pin
Covean25-Mar-10 22:13
Covean25-Mar-10 22:13 
GeneralRe: Data encryption Pin
Code-o-mat25-Mar-10 22:32
Code-o-mat25-Mar-10 22:32 
GeneralRe: Data encryption Pin
Covean25-Mar-10 23:05
Covean25-Mar-10 23:05 
GeneralRe: Data encryption Pin
Code-o-mat25-Mar-10 23:07
Code-o-mat25-Mar-10 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.