2024-07-25 08:11 AM - last edited on 2024-07-25 08:44 AM by Andrew Neil
Hello, I imported a project on STM32CubeIDE V1.9.
But when i compile, i have many errors (nearly 760) like this :
d:\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Application ino/Src/ino_1_IO.o:C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h:21: multiple definition of `Gestion_INPUT'; ./Application ino/Src/ino_0_Application.o:C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h:21: first defined here
The error is on declarations of a typedef or enum on a header files.
Few struct are declared like this :
typedef struct
{
uint8_t OldState_1;
uint8_t Flag_IN_1;
uint8_t Flag_OUT_1;
uint8_t TIMER_1;
uint8_t OldState_2;
uint8_t TIMER_2;
uint8_t OldState_3;
uint8_t TIMER_3;
uint8_t OldState_4;
uint8_t Flag_IN_4;
uint8_t Flag_OUT_4;
uint8_t TIMER_4;
}GESTION_IO;
GESTION_IO Gestion_INPUT, Gestion_OUTPUT;
the headers files are include in all C file of the software.
Have you got an idea to solve my problem?
Thanks in advance for your help
Solved! Go to Solution.
2024-07-25 08:30 AM - edited 2024-07-25 09:04 AM
The error is telling you that you have multiple definitions of Gestion_INPUT:
So it looks like you are defining the variable in you header - don't do that!
Your header should just contain the extern declaration - the definition should be in a .c file.
EDITs:
And here's a full example:
Further edit:
@st_user wrote:The error is on declarations of a typedef or enum on a header files.
No. The error is on the definition of the variable - Gestion_INPUT - not the definition of the typedef.
This is the typedef definition:
typedef struct
{
uint8_t OldState_1;
uint8_t Flag_IN_1;
uint8_t Flag_OUT_1;
uint8_t TIMER_1;
uint8_t OldState_2;
uint8_t TIMER_2;
uint8_t OldState_3;
uint8_t TIMER_3;
uint8_t OldState_4;
uint8_t Flag_IN_4;
uint8_t Flag_OUT_4;
uint8_t TIMER_4;
} GESTION_IO;
That should stay in the header.
This is the definition of the variable (actually, two variables) of that type:
GESTION_IO Gestion_INPUT, Gestion_OUTPUT;
That should not be in the header.
The header should have just the extern declaration:
extern GESTION_IO Gestion_INPUT, Gestion_OUTPUT;
The definition should be in one - and only one - .c file.
For how to properly post source code (as above) see:
2024-07-25 08:30 AM - edited 2024-07-25 09:04 AM
The error is telling you that you have multiple definitions of Gestion_INPUT:
So it looks like you are defining the variable in you header - don't do that!
Your header should just contain the extern declaration - the definition should be in a .c file.
EDITs:
And here's a full example:
Further edit:
@st_user wrote:The error is on declarations of a typedef or enum on a header files.
No. The error is on the definition of the variable - Gestion_INPUT - not the definition of the typedef.
This is the typedef definition:
typedef struct
{
uint8_t OldState_1;
uint8_t Flag_IN_1;
uint8_t Flag_OUT_1;
uint8_t TIMER_1;
uint8_t OldState_2;
uint8_t TIMER_2;
uint8_t OldState_3;
uint8_t TIMER_3;
uint8_t OldState_4;
uint8_t Flag_IN_4;
uint8_t Flag_OUT_4;
uint8_t TIMER_4;
} GESTION_IO;
That should stay in the header.
This is the definition of the variable (actually, two variables) of that type:
GESTION_IO Gestion_INPUT, Gestion_OUTPUT;
That should not be in the header.
The header should have just the extern declaration:
extern GESTION_IO Gestion_INPUT, Gestion_OUTPUT;
The definition should be in one - and only one - .c file.
For how to properly post source code (as above) see:
2024-07-25 09:54 AM
Perhaps stop defining things everywhere? That'd help a lot..
extern GESTION_IO Gestion_INPUT, Gestion_OUTPUT; // In the INCLUDE file
GESTION_IO Gestion_INPUT, Gestion_OUTPUT; // In ONE SOURCE FILE
2024-07-25 10:09 AM
@st_user wrote:the headers files are include in all C file of the software.
Think about it: if the header file contains the definition, then including that header file in multiple C files means that you are bound to have multiple definitions in the project!
2024-08-02 12:17 AM
Thanks for replies.
We have done your solution and it's work.