C to C++ link error
-
I'm trying to convert a C program into a VC++ program and have everything compiling but I get a ton of Link errors. The error I get is: error LNK2005: ... already defined in ... I'm getting 230+ of these error and don't really know why. I've used #pragam once in all the headers, but still get this error. Any help on this error or converting C to C++? Thanks, Jim
-
I'm trying to convert a C program into a VC++ program and have everything compiling but I get a ton of Link errors. The error I get is: error LNK2005: ... already defined in ... I'm getting 230+ of these error and don't really know why. I've used #pragam once in all the headers, but still get this error. Any help on this error or converting C to C++? Thanks, Jim
Does the symbol correspond to a global variable? Something like this?
int global;
If so, try writing this in the
.h
file:extern int global;
and then this in just one
.cpp
:int global=0;
If this works and you're curious, I can try to explain the reason of your problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Does the symbol correspond to a global variable? Something like this?
int global;
If so, try writing this in the
.h
file:extern int global;
and then this in just one
.cpp
:int global=0;
If this works and you're curious, I can try to explain the reason of your problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif
-
Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif
remove extern D2N_GLBL_STRUCT *D2N_GLBL;
??????? What is that
remove
thing? Could you explain what this file (is it a header?) is supposed to do, and what role does the macroELABORATE_ALL_VARIABLES
play? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif
-
I wish I knew, but I've never seen the program run before! I'm just having to port it to C++. The remove was something I forgot to remove when debugging. I think that this Macro does two different things based on what function is using it.
Ok. We can try to make an educated guess :) My opinion is that the header is used both for declaring things and for defining them. The second use is activated by
ELABORATE_ALL_VARIABLES
. Let's say the header is calleda.h
: then I guess you have to#include
it like always everywhere except in the one filea.cpp
, where you should have to write:// a.cpp
#define ELABORATE_ALL_VARIABLES
#include "a.h"
... // rest of stuffor, alternatively, define this macro for
a.cpp
in the properties section of the file (Fileview pane->right click ona.cpp
->Settings->Preprocessor definitions). Good luck. Let me know if I can give you more assistance. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo