2024-04-03 02:30 AM
Hi,
I am building my application which can be found here.
I get many errors of which mostly about multiple definition of variable. However, when I search through the code, I dont see a second definition. For example, _i2cAddress is only defined once in PCA9685.h as below
byte _i2cAddress;
Could you please help me resolve this issue ?
Thank you.
12:24:49 **** Incremental Build of configuration Debug for project PCA9685 ****
make -j8 all
arm-none-eabi-gcc -o "PCA9685.elf" @"objects.list" -mcpu=cortex-m4 -T"C:\Users\bjvyhb\OneDrive - PHINIA\Desktop\MCU\Workspace\RTOS_Workspace\PCA9685\STM32F407VGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="PCA9685.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.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:203: multiple definition of `_i2cAddress'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:203: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:205: multiple definition of `_i2cWire'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:205: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:206: multiple definition of `_i2cSpeed'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:206: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:208: multiple definition of `_driverMode'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:208: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:209: multiple definition of `_enabledMode'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:209: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:210: multiple definition of `_disabledMode'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:210: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:211: multiple definition of `_updateMode'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:211: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:212: multiple definition of `_phaseBalancer'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:212: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:213: multiple definition of `_isProxyAddresser'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:213: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:214: multiple definition of `_lastI2CError'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:214: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:253: multiple definition of `_coeff'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:253: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:254: multiple definition of `_isCSpline'; ./Core/Src/PCA9685.o:C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Inc/PCA9685.h:254: first defined here
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/PCA9685.o: in function `init_1':
C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:225: undefined reference to `writeRegister'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:226: undefined reference to `writeRegister'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/PCA9685.o: in function `setPWMFrequency':
C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:348: undefined reference to `writeRegister'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:349: undefined reference to `writeRegister'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:352: undefined reference to `writeRegister'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/PCA9685.o: in function `getChannelPWM':
C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:475: undefined reference to `i2cWire_requestFrom'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:478: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:489: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:490: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:491: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:492: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/PCA9685.o: in function `writeChannelEnd':
C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:756: undefined reference to `i2cWire_endTransmission'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/PCA9685.o: in function `readRegister':
C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:796: undefined reference to `i2cWire_requestFrom'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:799: undefined reference to `i2cWire_read'
C:/ST/STM32CubeIDE_1.14.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.100.202309141235/tools/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/bjvyhb/OneDrive - PHINIA/Desktop/MCU/Workspace/RTOS_Workspace/PCA9685/Debug/../Core/Src/PCA9685.c:810: undefined reference to `i2cWire_read'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:64: PCA9685.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.
12:24:52 Build Failed. 28 errors, 0 warnings. (took 2s.910ms)
Solved! Go to Solution.
2024-04-03 02:43 AM - edited 2024-04-03 06:48 AM
@demir wrote:_i2cAddress is only defined once in PCA9685.h as below
byte _i2cAddress;
There's your problem!
Don't define the variables in a header!
When you do that, you will get a definition everywhere that you #include that header - if you #include the header in multiple places, you will get multiple definitions!
Your header should contain just the extern declaration; the definition should be in a .c file somewhere.
This is standard C stuff - nothing specific to STM32:
https://c-faq.com/decl/decldef.html
#DeclDef #MultipleDefinitions
2024-04-03 02:43 AM - edited 2024-04-03 06:48 AM
@demir wrote:_i2cAddress is only defined once in PCA9685.h as below
byte _i2cAddress;
There's your problem!
Don't define the variables in a header!
When you do that, you will get a definition everywhere that you #include that header - if you #include the header in multiple places, you will get multiple definitions!
Your header should contain just the extern declaration; the definition should be in a .c file somewhere.
This is standard C stuff - nothing specific to STM32:
https://c-faq.com/decl/decldef.html
#DeclDef #MultipleDefinitions
2024-04-03 02:46 AM - edited 2024-04-03 02:50 AM
(never mind)
2024-04-05 12:27 AM
@Andrew Neil wrote:Your header should contain just the extern declaration; the definition should be in a .c file somewhere.
For a complete example, see: