IAR Error[Li006] 'duplicate definitions' - but not on CubeIDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 12:59 AM - last edited on ‎2025-03-14 3:45 AM by Andrew Neil
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?
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:43 AM
You're right,
In the CubeIDE it is defined the flag -fcommon for the compiler
Is there a way to set it in IAR as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 3:42 AM - edited ‎2025-03-14 3:44 AM
@nico23 wrote: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.
So don't do that, then!
@nico23 wrote:The question is why CubeIDE ignore this issue
It's not the IDE; it's the compiler - ie, GCC.
GCC does (did?), indeed, have the option to do this.
You didn't say what CubeIDE version you're using - that would dictate the GCC version.
PS:
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 3:56 AM
First, some code / headers is toolchain-specific,
For IAR, this is "_ICC" if I remember correctly.
So, look for instances of "#ifdef _ICC" or "#ifndef _ICC" vs. "#ifdef GCC" surrounding the problematic code.
> 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.
Not sure what you are doing.
While defining variable in .h files is not strictly forbidden, it is very bad practice.
You can declare them as often as desired, but define them only once.
And a linker error is the result of defining it more than once.
As a side note, IAR WB has a certain "feature" to define a "pre include", i.e. an include that is always included first.
This might be preset to a default when creating the project.
I would remove any such entry, as it is incompatible with all other toolchains..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:03 AM
@Andrew Neil wrote:
@nico23 wrote: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.
So don't do that, then!
It's legacy code. I didn't wrote it.
@nico23 wrote:The question is why CubeIDE ignore this issue
It's not the IDE; it's the compiler - ie, GCC.
GCC does (did?), indeed, have the option to do this.
You didn't say what CubeIDE version you're using - that would dictate the GCC version.
I'm using CubeIDE 1.18 (from what I understand it's using GNU Tools 13.3.rel1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:13 AM
@Ozone wrote:While defining variable in .h files is not strictly forbidden, it is very bad practice.
That's the thing. The code defines the variables in the .h file and in various .c file.
For istance I have a struct bed {} in the main.h and struct bed signal in both main.c and task.c
The CubeIDE doesn't seem to bother, instead IAR raises Linker Error[Li006]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:25 AM
I would not suspect an issue with gcc, which is quite good. Or IAR, for that matter.
Rather, with the project setup.
I would recommend to check all project sources for occurences/definitions/declarations of this variable.
And especially the map file, which *.o files finally export the same symbol.
Perhaps you have added the same (or similiar) file twice to the project, or two files that don't go together in the same project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:28 AM
@nico23 wrote:The CubeIDE doesn't seem to bother, instead IAR raises Linker Error[Li006]
Specifically, it's GCC - again, see:
So maybe the Cube project has been specifically configured to allow the "common" definitions - overriding that changed default?
https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#:~:text=%2Dfcommon,link%20without%20errors.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:36 AM
@Ozone wrote:As a side note, IAR WB has a certain "feature" to define a "pre include", i.e. an include that is always included first.
This might be preset to a default when creating the project.
I would remove any such entry, as it is incompatible with all other toolchains..
GCC and, thus, CubeIDE do also have that facility:
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Preprocessor-Options.html#index-include
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:43 AM
You're right,
In the CubeIDE it is defined the flag -fcommon for the compiler
Is there a way to set it in IAR as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-14 4:58 AM
Excellent - so you can mark that as the solution:
https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256
@nico23 wrote:Is there a way to set it in IAR as well?
You'd have to ask IAR that.
Does their documentation of their [Li006] error make any suggestions?
Or maybe it's just time to fix the code?
A complex system designed from scratch never works and cannot be patched up to make it work.
