cancel
Showing results for 
Search instead for 
Did you mean: 

Error [LI006] - STM32L1xx - IAR - Linker error: Duplicate Definition

valeriogiampa
Associate II
Posted on February 12, 2012 at 01:30

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-definitions
19 REPLIES 19
william239955
Associate II
Posted on April 06, 2012 at 12:04

Yes, this is just I did, the only declaration is in init.h, and it is affected by a value in init.c. There is no any other declaration. This is why I can not understand where is the pb.

frankmeyer9
Associate II
Posted on April 06, 2012 at 12:24

> the only declaration is in init.h

This can't work, you can't do a definition and a declaration at once.

Say, you have a file

init.c

(going back to your example).

Add a definition there, like:

extern int  aver = 0;

You need to do it outside of any function. Then, add a declaration in

init.h

(you have it already)...

extern int  aver;

The best choice is to make this declaration visible only to modules other than

init.c

, otherwise you get an warning about 'initializing and declaring it extern'.

Include

init.h

in

main.c

.

Then, you can access your variable in main.c.

Posted on April 06, 2012 at 14:01

This is why I can not understand where is the pb.

Good grief! This is pretty basic C stuff when using multiple source files. You can only physically define the variable once, otherwise you'll get ''multiple definitions'', other files must understand they are referring to an external variable so you don't get secondary definitions.

init.h -> extern int aver;

init.c -> int aver = 0;

main.c -> #include ''init.h

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
william239955
Associate II
Posted on April 06, 2012 at 14:39

Thank you very much, that's good.

Andrew Neil
Evangelist III
Posted on April 06, 2012 at 21:25

''Good grief! This is pretty basic C stuff''

 

Indeed it is, and yet it is such a common mistake!

I think there must be something seriously wrong with the teaching of programming these days!

http://c-faq.com/decl/decldef.html

frankmeyer9
Associate II
Posted on April 07, 2012 at 12:39

I'm not aware of any such teaching facility being bent toward embedded systems/programming.

And C, at least according to my impression, is much too far ''low level'' for most institutions. It seems very few of todays students want to dig down to machine and register level.

About 20 years ago, I had C language lessons as student, missing Fortran by just one year. These lessons, however, were much worse than my self-teaching lessons from a book...

Posted on April 07, 2012 at 13:54

About 20 years ago, I had C language lessons as student, missing Fortran by just one year. These lessons, however, were much worse than my self-teaching lessons from a book...

 

 

This would mirror my experience, the people thrown at us to teach Assembler, PASCAL and C, were rather ill suited to the task, I just digested a lot of books and data sheets. A better teaching route might be to focus on problem solving and logical thinking.

That said, the resources available to someone 20-30 years hence are significantly better, indexed and searchable to a large degree, and at the click of a button. I can't speak to whether the teaching profession has gotten any better, but my encounters with the products of the system would probably suggest not so much.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on April 07, 2012 at 20:06

> but my encounters with the products of the system would probably suggest not so much.

Totally need to agree here.

A lot of embedded developer i knew and know are characterized as ''lateral entrants''. This applies as well to me, coming quite late to bare- metal embedded development and ARM controllers especially.

Todays computer science seems more about Java, C# and .NET, data bases and XML - rarely anybody is getting down to register level, and enjoys getting something to work with limited ressources.

> This would mirror my experience, the people thrown at us to teach Assembler, PASCAL and C, were rather ill suited to the task,

A nice opportunity to cite Gary North, a economics expert:

''Those who can, do.

Those, who can't, teach.

Those who can't even teach, administer.''

Happy Eastern !

Andrew Neil
Evangelist III
Posted on April 09, 2012 at 12:49

''I'm not aware of any such teaching facility being bent toward embedded systems/programming.''

There are plenty of organisations that provide specific embedded training; I mention a few that I know of here:

http://blog.antronics.co.uk/2010/12/12/things-you-shouldve-learned-in-c-class-0-introduction/

But this apparent lack of good teaching one thing that prompted it: ''Hopefully, educators may also find these posts useful in considering whether any changes in their material or presentation might be beneficial…''

My aim of an ''occasional series''  hasn't done too well, though!

frankmeyer9
Associate II
Posted on April 09, 2012 at 14:23

That might depend on location.

Saying ''I'm not aware of'', I'm not implying they do not exist.

I never met anybody in my career having graduated from such an educational facility, and being well educated in both embedded systems and software design. A lot people I know in this field are good at one of those fields, but not both. And the majority were autodidacts in the embedded field.

I can hardly fend off the impression that this field is viewed as somehow non-rewarding for universities. This might depend on the style of education financing - I mainly talk about central europe here.