2012-02-11 04:30 PM
Hi,
I have modified an example project of IAR for STM32L1XX with a new library definition (one file .c and one file .h). In the file .h I have defined a variable that I use in the .c file. The function defined in the .h file are developed in the .c file and used in the main file. There aren't any duplicate of the variable that I have defined in the .h file, but when I run the make command I can see this message: Linking Error[Li006]: duplicate definitions for ''ADC_Counter''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Delay''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\ RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\RAM_Debug\ Obj\main.o'' Error[Li006]: duplicate definitions for ''Frequency''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\ RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\RAM_Debug\ Obj\main.o'' Error[Li006]: duplicate definitions for ''Frequency_Detection''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Gate_Pulse_Off''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Half_Period_Length''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''LED_Blinking''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Period''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\ RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\RAM_Debug\ Obj\main.o'' Error[Li006]: duplicate definitions for ''Period_Counter''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Period_Length''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Period_Prev''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Power_Level''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Power_Level_Prev''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Second_Half_Wave''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Soft_Change_Delay''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Soft_Change_Speed''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Start_Up''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\ RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\RAM_Debug\ Obj\main.o'' Error[Li006]: duplicate definitions for ''Timer''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\ RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\GettingStarted-VG1\RAM_Debug\ Obj\main.o'' Error[Li006]: duplicate definitions for ''Trimmer_Value''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''Turn_On_Delay''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''ZVS_Alarm''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error[Li006]: duplicate definitions for ''ZVS_Alarm_Counter''; in ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\appSource.o'', and ''C:\Users\hp\Desktop\STM32L1xx\Demos_STM32-P152_v1.00\Demos\Projects\ GettingStarted-VG1\RAM_Debug\Obj\main.o'' Error while running Linker Total number of errors: 22 Total number of warnings: 0 One error for variable defined in the .h file. Why? Can you help me? Best Regards Valerio #error-li006-duplicate-error-iar #li006-duplicate-definitions2012-02-11 05:13 PM
One error for variable defined in the .h file. Why? Can you help me?
Yet you don't provide the file(s) to examine, or a brief snap-shot. If I have to guess, you are defining variables without using ''extern'' and consequently every file which includes your .H creates a copy of the variable. foo.h -> extern int bar; foo.c -> int bar = 0; main.c -> #include ''foo.h''2012-02-17 08:27 AM
2012-04-06 01:16 AM
I have the same pb, my usage is like follows:
#ifdef INIT_AVER init.h -> int aver; init.c -> aver = 0; #endif main.c -> #include ''init.h''2012-04-06 01:17 AM
I have the same pb, my usage is like follows:
#ifdef INIT_AVER init.h -> int aver; init.c -> aver = 0; #endif main.c -> #include ''init.h''2012-04-06 01:28 AM
Try this:
init.h -> extern int aver;2012-04-06 01:31 AM
I have the same pb, my usage is like follows:
init.h -> #ifdef INIT_AVER init.h -> int aver; init.h -> #endif init.c -> aver = 0; main.c -> #include ''init.h''2012-04-06 01:38 AM
Thanks, I will try.
2012-04-06 01:52 AM
When I use ''extern'' in init.h, I got the following error:
Error[Li005]: no definition for ''aver'' [referenced from ....\main.o]2012-04-06 02:40 AM
Your distribution of declaration in source files is not clear to me from this posts.
However, one file should define the questioned variable:int variable = 0;
or:extern int variable = 0;
The other file should see a declaration, for instance from a header:extern int variable;
Each variable must be defined once and only once, but can be declared multiple times. See a C language manual for the difference between definition and declaration.