Link Error S12G

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link Error S12G

1,183 Views
rayhall
Contributor V

I keep getting this link error telling me I have duplicated value in two files. I have checked many times and cannot find the error. Can I have someone see what I am missing. I have included he whole program code

Thank You.

Ray..

 

 

0 Kudos
4 Replies

1,178 Views
lama
NXP TechSupport
NXP TechSupport

I would like to suggest you to manage global variables correctly....

I you use them then create them in a one extra file with the keyword extern.

There are more errors reported in the file. Not only presented in the question.

I do not want to study the logic of your application. First of all you have to process global variables on the basis of other error reports.

For example simple check (search in files) of the variable cntErrorRetry:

(defined twice as a global variable, but not only defined but also initialized twice. The common global variable can be defined and initialized only once. Of course, the only defined can be in any module if you use keyword " extern"  but initialized only once.)

lama_0-1605521869409.png

 

Best regards,

Ladislav

 

0 Kudos

1,166 Views
rayhall
Contributor V

Ladislav,

Is there anywhere I can learn about  managing global variables correctly.

If you did see global values  initialized twice. Where were they I cannot find them.

I am 67 and a self taught programmer so will have many bad rabbits

Ray.

0 Kudos

1,157 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

entire web is full of explanation how to use global variables in C.

However, when I want to use variable defined in some module (let's say file1.c) as global and make it visible to other modules then I define it in the file1.h as extern and as global in the module file1.c.

file1.h: extern UBYTE var1;

file1.c: UBYTE var 1 = 10;

This approach I use when the variable is closely connected to given module functionality and I want to create connection of its global variables to other modules.

However, if I have some variables I want to be global for each module..like program setup values, general counters,....then I create extra globalDefs.c and GlobalDefs.h where I create such variables (myCounter in the example in module myfile1.c/h).

I have attached an example you can step through and look into variables window which variable is processed.


(Of course, the CodeWarrior provides some simplification in usage of keyword extern but I use it to inform myself I did everything and know how the variable will be used)

The main problem, I think, in your project is a multiply initialization of commonly used global variables as a part of definition.

 

Best regards,
Ladislav

0 Kudos

1,154 Views
rayhall
Contributor V

Thank you for the example.

Ray.

0 Kudos