cancel
Showing results for 
Search instead for 
Did you mean: 

Merging header file into source file multiple declaration error is coming?

MDeva.1
Associate II

Hello,

I am creating the header and source file according to the IC. Two Ic I interface and created its header file particular ,but when I tried to add header file in second source file I getting this and errors. I am unable to understand why its errors are come There are 2 core ,core M4 and M7.In both core the IO.h are defined when I tried to add this file to any source files it through errors.

make -j4 all 

arm-none-eabi-gcc "../Core/Src/Temp.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32H745xx -c -I../Core/Inc -I../../Drivers/STM32H7xx_HAL_Driver/Inc -I../../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy -I../../Drivers/CMSIS/Device/ST/STM32H7xx/Include -I../../Drivers/CMSIS/Include -I../USB_DEVICE/App -I../USB_DEVICE/Target -I../../Middlewares/ST/STM32_USB_Device_Library/Core/Inc -I../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/Temp.d" -MT"Core/Src/Temp.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/Temp.o"

arm-none-eabi-gcc -o "PL_REV1_CM4.elf" @"objects.list"  -mcpu=cortex-m4 -T"D:\Project\PL_REV1\CM4\STM32H745IIKX_FLASH.ld" --specs=nosys.specs -Wl,-Map="PL_REV1_CM4.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:19: multiple definition of `PCAL6524_ADDRESS_0'; ./Core/Src/IO.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:19: first defined here

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:20: multiple definition of `PCAL6524_ADDRESS_1'; ./Core/Src/IO.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:20: first defined here

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:21: multiple definition of `PCAL6524_ADDRESS_2'; ./Core/Src/IO.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:21: first defined here

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:22: multiple definition of `PCAL6524_ADDRESS_3'; ./Core/Src/IO.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:22: first defined here

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:28: multiple definition of `PCAL6524_INPUT_PORT_0'; ./Core/Src/IO.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:28: first defined here

c:\st\stm32cubeide_1.8.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: ./Core/Src/Temp.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:29: multiple definition of `PCAL6524_INPUT_PORT_1';

5 REPLIES 5

No, what you're probably doing is defining variable(s) in an include file, which is a no-no.

The include file should have prototypes and externs, and the functions and variables defined ONCE in a source file.

Include files should not have code in them.

IO.c and IO.h need to be worked on.

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

When I try to add IO.h in IO.c its working fime but when I try to add this file in main.c or temp.c it throw errors.I am sharing the the snap of my files, i am unable to understand why its erroe comes.0693W00000KdUKOQA3.png0693W00000KdUKEQA3.png0693W00000KdUK4QAN.png

>> i am unable to understand why its error

It SPECIFICALLY tells you it's those variables you're defining as const.

Put those in IO.C, or use #define's or enum's

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

Thank you the error gets solve​

PHolt.1
Senior III

Cube 1.9 introduces this error into many projects, because it changes the GCC compiler from v9 to v10.

https://www.eevblog.com/forum/microcontrollers/is-st-cube-ide-a-piece-of-buggy-crap/msg4068004/#msg4068004