Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   MPLink Error (http://www.chiefdelphi.com/forums/showthread.php?t=33822)

cloudago 01-02-2005 22:41

MPLink Error
 
We ran into a problem when we tried defining unsigned chars in a header file and running into a Linker error that claimed that a variable had multiple definitions.

This is what we have in the header file which causes the error:
long int KP_P = 5;

This is the error given by the Linker:
Error - symbol 'KP_P' has multiple definitions.

This source code does not cause an error:
#define KP_P (5)

Declaring the variable as a long int in the *.c file does not cause any errors, it is only in the header file that it causes the error.

Has anyone run into this error or is it a bug in the Linker?

probizzle 01-02-2005 23:00

Re: MPLink Error
 
It is not a bug in the linker.

When you declare a long int in the header file, every time a .c includes this header file, space will be allocated for KP_P. Even if you have the #ifndef __header_file_name_h_ #define __header_file_name_h_ at the top of the file.

Here is the solution:

declare lont int KP_P in a .c file.
However, also
add
Quote:

extern long int KP_P;
in the header file.
Now, if you include this header file, you should be able to use KP_P.

Another comment:
the define doesn't show an error, because it is essentially a copy paste operation, and the compiler is smart enough to figure it out.

Mike Betts 01-02-2005 23:00

Re: MPLink Error
 
This is not a bug. KP_P is defined somewhere else. Either fiond out where or change the variable name.


All times are GMT -5. The time now is 07:31.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi