Multiple definitions of... error | first defined here... Build Failure

Greetings,

I saw other similar posts but all were for .json files and other things that confused me.

I have a cpp project and I am showing the file tree here:
PIO

This is the exact error code.

.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.bss.cmd+0x0): multiple definition of `cmd'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.cmd+0x0): first defined here
c:/users/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.V_DIVIDER+0x0): multiple definition of `V_DIVIDER'
.pio\build\teensy41\src\ADE.cpp.o:(.data.V_DIVIDER+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.MCU_LED5+0x0): multiple definition of `MCU_LED5'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED5+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.MCU_LED4+0x0): multiple definition of `MCU_LED4'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED4+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.MCU_LED3+0x0): multiple definition of `MCU_LED3'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED3+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.MCU_LED2+0x0): multiple definition of `MCU_LED2'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED2+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.MCU_LED1+0x0): multiple definition of `MCU_LED1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED1+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.I2C_EN+0x0): multiple definition of `I2C_EN'
.pio\build\teensy41\src\ADE.cpp.o:(.data.I2C_EN+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.PM1+0x0): multiple definition of `PM1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM1+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.PM0+0x0): multiple definition of `PM0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM0+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.ADE_RESET+0x0): multiple definition of `ADE_RESET'
.pio\build\teensy41\src\ADE.cpp.o:(.data.ADE_RESET+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.IRQ_0+0x0): multiple definition of `IRQ_0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_0+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.IRQ_1+0x0): multiple definition of `IRQ_1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_1+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.bss.previousMillis+0x0): multiple definition of `previousMillis'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.previousMillis+0x0): first defined here
.pio\build\teensy41\src\ADE_Calculations.cpp.o:(.data.period+0x0): multiple definition of `period'
.pio\build\teensy41\src\ADE.cpp.o:(.data.period+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.bss.cmd+0x0): multiple definition of `cmd'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.cmd+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.V_DIVIDER+0x0): multiple definition of `V_DIVIDER'
.pio\build\teensy41\src\ADE.cpp.o:(.data.V_DIVIDER+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.MCU_LED5+0x0): multiple definition of `MCU_LED5'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED5+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.MCU_LED4+0x0): multiple definition of `MCU_LED4'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED4+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.MCU_LED3+0x0): multiple definition of `MCU_LED3'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED3+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.MCU_LED2+0x0): multiple definition of `MCU_LED2'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED2+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.MCU_LED1+0x0): multiple definition of `MCU_LED1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED1+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.I2C_EN+0x0): multiple definition of `I2C_EN'
.pio\build\teensy41\src\ADE.cpp.o:(.data.I2C_EN+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.PM1+0x0): multiple definition of `PM1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM1+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.PM0+0x0): multiple definition of `PM0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM0+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.ADE_RESET+0x0): multiple definition of `ADE_RESET'
.pio\build\teensy41\src\ADE.cpp.o:(.data.ADE_RESET+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.IRQ_0+0x0): multiple definition of `IRQ_0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_0+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.IRQ_1+0x0): multiple definition of `IRQ_1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_1+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.bss.previousMillis+0x0): multiple definition of `previousMillis'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.previousMillis+0x0): first defined here
.pio\build\teensy41\src\ADE_Config.cpp.o:(.data.period+0x0): multiple definition of `period'
.pio\build\teensy41\src\ADE.cpp.o:(.data.period+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.bss.cmd+0x0): multiple definition of `cmd'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.cmd+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.V_DIVIDER+0x0): multiple definition of `V_DIVIDER'
.pio\build\teensy41\src\ADE.cpp.o:(.data.V_DIVIDER+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.MCU_LED5+0x0): multiple definition of `MCU_LED5'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED5+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.MCU_LED4+0x0): multiple definition of `MCU_LED4'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED4+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.MCU_LED3+0x0): multiple definition of `MCU_LED3'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED3+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.MCU_LED2+0x0): multiple definition of `MCU_LED2'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED2+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.MCU_LED1+0x0): multiple definition of `MCU_LED1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED1+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.I2C_EN+0x0): multiple definition of `I2C_EN'
.pio\build\teensy41\src\ADE.cpp.o:(.data.I2C_EN+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.PM1+0x0): multiple definition of `PM1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM1+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.PM0+0x0): multiple definition of `PM0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM0+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.ADE_RESET+0x0): multiple definition of `ADE_RESET'
.pio\build\teensy41\src\ADE.cpp.o:(.data.ADE_RESET+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.IRQ_0+0x0): multiple definition of `IRQ_0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_0+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.IRQ_1+0x0): multiple definition of `IRQ_1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_1+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.bss.previousMillis+0x0): multiple definition of `previousMillis'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.previousMillis+0x0): first defined here
.pio\build\teensy41\src\ADE_I2C.cpp.o:(.data.period+0x0): multiple definition of `period'
.pio\build\teensy41\src\ADE.cpp.o:(.data.period+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.bss.cmd+0x0): multiple definition of `cmd'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.cmd+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.V_DIVIDER+0x0): multiple definition of `V_DIVIDER'
.pio\build\teensy41\src\ADE.cpp.o:(.data.V_DIVIDER+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.MCU_LED5+0x0): multiple definition of `MCU_LED5'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED5+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.MCU_LED4+0x0): multiple definition of `MCU_LED4'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED4+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.MCU_LED3+0x0): multiple definition of `MCU_LED3'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED3+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.MCU_LED2+0x0): multiple definition of `MCU_LED2'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED2+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.MCU_LED1+0x0): multiple definition of `MCU_LED1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.MCU_LED1+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.I2C_EN+0x0): multiple definition of `I2C_EN'
.pio\build\teensy41\src\ADE.cpp.o:(.data.I2C_EN+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.PM1+0x0): multiple definition of `PM1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM1+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.PM0+0x0): multiple definition of `PM0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.PM0+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.ADE_RESET+0x0): multiple definition of `ADE_RESET'
.pio\build\teensy41\src\ADE.cpp.o:(.data.ADE_RESET+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.IRQ_0+0x0): multiple definition of `IRQ_0'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_0+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.IRQ_1+0x0): multiple definition of `IRQ_1'
.pio\build\teensy41\src\ADE.cpp.o:(.data.IRQ_1+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.bss.previousMillis+0x0): multiple definition of `previousMillis'
.pio\build\teensy41\src\ADE.cpp.o:(.bss.previousMillis+0x0): first defined here
.pio\build\teensy41\src\ADE_Parser.cpp.o:(.data.period+0x0): multiple definition of `period'
.pio\build\teensy41\src\ADE.cpp.o:(.data.period+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\teensy41\firmware.elf] Error 1

Now I have 5 cpp files, with everything needed for them defined/included in the ADE_Header.h file… then I essentially do a

#include "ADE_Header.h" // in each cpp file. note: I have "#pragma once" in this header file

But I see that the issue is coming from the .pio folder stuff. Where I see the .cpp.o version of my cpp files, but I don’t see a header file anywhere in the .pio folder… Am I suppose to move my header around? Why wouldn’t that automatically be taken care of?

How do I deal with this? Am I using the headers incorrectly? Is there some configuration thing I am suppose to do? Thanks.

That is good but not sufficient. If you don’t declare global variables in this header file as extern, this will cause a multiple definition in every single .cpp file that includes this header.

This has e.g. been discussed in Splitting cpp files - #2 by maxgerhardt

1 Like