cancel
Showing results for 
Search instead for 
Did you mean: 

IAR Error[Li006] 'duplicate definitions' - but not on CubeIDE

nico23
Senior II

I'm trying to move my project from CubeIDE to IAR 9.20.4

For some reason I'm gettin Linker Error[Li006] duplicate definitions.

With CubeIDE I'm able to compile and debug/download with no issue.

I know the error is due to the fact I'm having variables on the .h files included in various .c files that are not set as external. 

The question is why CubeIDE ignore this issue and the IAR do not?

10 REPLIES 10
CTapp.1
Senior II

The use of something like:

int x;

within a header file is, according to the C Standard, a tentative definition.

Any tentative definition for which an actual definition does not exist within a translation unit becomes a definition at the end of the translation unit when it is compiled. This means that the above use within a header file does result in multiple definitions of x if the header file is included in multiple translation units.

It is therefore perfectly reasonable for IAR to issue a diagnostic, but the standard does not require this behaviour (it is a link-time issue). GCC will do the same with the default -fno-common, but not with -fcommon.

As @Andrew Neil says above, it really is much better to use extern.