cancel
Showing results for 
Search instead for 
Did you mean: 

"Multiple definition" Error compilation of typedef on header file

st_user
Associate

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

The error is telling you that you have multiple definitions of Gestion_INPUT:

  1. in the file ./Application ino/Src/ino_1_IO.c from the header C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h at line 21;
  2. in the file ./Application ino/Src/ino_0_Application.c from the header C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h at line 21

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:

https://community.st.com/t5/stm32cubeide-mcus/build-issue-as-variable-defined-once-more-however-it-is-only/m-p/657254/highlight/true#M25815

And here's a full example:

https://community.st.com/t5/stm32cubeide-mcus/adding-new-c-source-files-to-my-project-and-navigating-through/m-p/657455/highlight/true#M25847

 

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:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

View solution in original post

4 REPLIES 4

The error is telling you that you have multiple definitions of Gestion_INPUT:

  1. in the file ./Application ino/Src/ino_1_IO.c from the header C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h at line 21;
  2. in the file ./Application ino/Src/ino_0_Application.c from the header C:/Users/innolife/STM32CubeIDE/workspace_1.9.0/PE30-V_V2.41-K_V2.2/Drivers/AX/Inc/AX_IO.h at line 21

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:

https://community.st.com/t5/stm32cubeide-mcus/build-issue-as-variable-defined-once-more-however-it-is-only/m-p/657254/highlight/true#M25815

And here's a full example:

https://community.st.com/t5/stm32cubeide-mcus/adding-new-c-source-files-to-my-project-and-navigating-through/m-p/657455/highlight/true#M25847

 

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:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@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!

st_user
Associate

Thanks for replies.

We have done your solution and it's work.