I am working with form application in VC++. I have main form i.e. Form1.h and also the child form named child.h. I am calling the child.h form on the button click of the form1.h. For calling the child.h I have to include Child.h in Form1.h.
I have used the following code
in Form1.h
#incude "Child.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Child^ c=gcnew Child;
c->Visible=true;
}
And In Child.h I am doing some processing. For this I have made one header file named param.h having some function name and global variables name. I have included param.h in Child.h file.
And param.h is
#ifndef param_h_seen
#define param_h_seen
#define LED_Line 4
#define CALIBRATION_MODE 0
typedef unsigned __int32 uint32_t;
typedef unsigned __int8 uint8_t;
/****for LED ROI entered by user***/
int x_of_roi=6;
int y_of_roi=10;
/********************************/
/*************for graph ROI*******/
int ROIwidth=16;
int ROIheight=4096;
/********************************/
int LED_num= 64;
unsigned short *calib_factor;
/*********functions*****************/
int find_area(unsigned char *intensity,int start);
void DetectRectangle();
/***************************************/
#endif
After Including the child.h It is showing the error
PUMA_LED_TESTER.obj : error LNK2005: "unsigned short * calib_factor" (?calib_factor@@3PAGA) already defined in Child.obj
PUMA_LED_TESTER.obj : error LNK2005: "int x_of_roi" (?x_of_roi@@3HA) already defined in Child.obj
PUMA_LED_TESTER.obj : error LNK2005: "int y_of_roi" (?y_of_roi@@3HA) already defined in Child.obj
PUMA_LED_TESTER.obj : error LNK2005: "int ROIwidth" (?ROIwidth@@3HA) already defined in Child.obj
PUMA_LED_TESTER.obj : error LNK2005: "int ROIheight" (?ROIheight@@3HA) already defined in Child.obj
PUMA_LED_TESTER.obj : error LNK2005: "int LED_num" (?LED_num@@3HA) already defined in Child.obj
I don’t know why these errors are coming.Can any body please tell me the solution to solve these errors
Thanks in Advance
Those are definitions, and should not be in your header files. Place them in one of the cpp files, and on the header have:
Same goes with the rest of the global variables you declare in your header files. When those headers are included by more than one cpp file (namely translation unit), each unit effectively declares new variables with the same name, which the linker complains about.