Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

When adding header file multiple declaration error is come

Status
Not open for further replies.

MD18

Junior Member level 3
Junior Member level 3
Joined
Dec 9, 2021
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
166
Hello,
I am working on stm32. I am using stm32cubeide ,I worked on 2 cores controller .I am IO.h and IO.c in both core.When I add the IO.h in IO.c its working fine when I try to add IO.h file in another source files it through errors below.

Code:
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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:20: multiple definition of `PCAL6524_ADDRESS_0'; ./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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:21: multiple definition of `PCAL6524_ADDRESS_1'; ./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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:22: multiple definition of `PCAL6524_ADDRESS_2'; ./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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:23: multiple definition of `PCAL6524_ADDRESS_3'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:23: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:29: multiple definition of `PCAL6524_INPUT_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:29: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:30: multiple definition of `PCAL6524_INPUT_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:30: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:31: multiple definition of `PCAL6524_INPUT_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:31: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:32: multiple definition of `PCAL6524_OUTPUT_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:32: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:33: multiple definition of `PCAL6524_OUTPUT_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:33: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:34: multiple definition of `PCAL6524_OUTPUT_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:34: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:35: multiple definition of `PCAL6524_POLARITY_INVERSION_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:35: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:36: multiple definition of `PCAL6524_POLARITY_INVERSION_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:36: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:37: multiple definition of `PCAL6524_POLARITY_INVERSION_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:37: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:38: multiple definition of `PCAL6524_CONFIGURATION_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:38: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:39: multiple definition of `PCAL6524_CONFIGURATION_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:39: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:40: multiple definition of `PCAL6524_CONFIGURATION_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:40: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:41: multiple definition of `PCAL6524_OUTPUT_STRENGH_OA'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:41: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:42: multiple definition of `PCAL6524_OUTPUT_STRENGH_0B'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:42: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:43: multiple definition of `PCAL6524_OUTPUT_STRENGH_1A'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:43: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:44: multiple definition of `PCAL6524_OUTPUT_STRENGH_1B'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:44: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:45: multiple definition of `PCAL6524_OUTPUT_STRENGH_2A'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:45: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:46: multiple definition of `PCAL6524_OUTPUT_STRENGH_2B'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:46: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:47: multiple definition of `PCAL6524_INPUT_LATCH_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:47: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:48: multiple definition of `PCAL6524_INPUT_LATCH_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:48: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:49: multiple definition of `PCAL6524_INPUT_LATCH_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:49: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:50: multiple definition of `PCAL6524_RESISTOR_PULL_ENABLE_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:50: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:51: multiple definition of `PCAL6524_RESISTOR_PULL_ENABLE_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:51: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:52: multiple definition of `PCAL6524_RESISTOR_PULL_ENABLE_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:52: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:53: multiple definition of `PCAL6524_RESISTOR_PULL_SELECTION_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:53: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:54: multiple definition of `PCAL6524_RESISTOR_PULL_SELECTION_PORT_1'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:54: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:55: multiple definition of `PCAL6524_RESISTOR_PULL_SELECTION_PORT_2'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:55: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:56: multiple definition of `PCAL6524_INTERRUPT_MASK_PORT_0'; ./Core/Src/Io_O:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:56: 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/main.o:D:/Project/PL_REV1/CM4/Debug/../Core/Inc/IO.h:57: multiple definition of `PCAL6524_INTERRUPT_MASK_PORT_1';



Capture.PNG
[/code]
 
Last edited by a moderator:

It seems like your header file doesnot have #ifndef at the beginning of file. So this header is being considered more than once in a single translation unit and you are getting multiple definition error.

Add the following #ifndef, #define header and #endif footer to your IO.h and try building again.
Code:
#ifndef IO_EXAMPLE_H_
#define IO_EXAMPLE_H_
/* Place to put all of your current IO.h contents */
#endif

If this doesnot work, attach the zip file of your whole project.
 

It seems like your header file doesnot have #ifndef at the beginning of file. So this header is being considered more than once in a single translation unit and you are getting multiple definition error.

Add the following #ifndef, #define header and #endif footer to your IO.h and try building again.
Code:
#ifndef IO_EXAMPLE_H_
#define IO_EXAMPLE_H_
/* Place to put all of your current IO.h contents */
#endif

If this doesnot work, attach the zip file of your whole project.
I am sharing the screesnshot of my files I alredy add the #ifndef and #endif but it throw the errors
pro.PNG
ifded.PNG
endif.PNG
 

What seems to be happening is that you are 'defining' the variables in the 'main.h' header file and then including the header in both the 'main.c' and the 'io.c' files. Are you sure that the 'main.h' has the #ifndef...#endif preprocessor directives in it?
The other way to do this is to declare your variables in the header file (possibly with 'extern' depending on exactly which language your are using) and then define each variable once in whichever .c file it belongs to.
(This approach does require that you understand the difference between declaring and defining a variable - there are multiple pages in the Internet that explains the difference if you are not sure.)
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top