Collect2: error: ld returned 1 exit status *** [.pio/build/esp12e/firmware.elf] Error 1

I have an ESP8266 project that compiled fine. As it growed I moved some parts WiFi and MQTT to separate files. now I get the following error.

Linking .pio/build/esp12e/firmware.elf /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsState+0x0): multiple definition of `gsState'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsState+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.client+0x0): multiple definition of `client'; .pio/build/esp12e/src/functions.cpp.o:(.bss.client+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.11.2+0x0): multiple definition of `mqttServer'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.11.2+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.lastMsg+0x0): multiple definition of `lastMsg'; .pio/build/esp12e/src/functions.cpp.o:(.bss.lastMsg+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.19.10+0x0): multiple definition of `gsPubState'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.19.10+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.espClient+0x0): multiple definition of `espClient'; .pio/build/esp12e/src/functions.cpp.o:(.bss.espClient+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.runTime+0x0): multiple definition of `runTime'; .pio/build/esp12e/src/functions.cpp.o:(.bss.runTime+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.22.13+0x0): multiple definition of `gsSubSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.22.13+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.21.12+0x0): multiple definition of `gsPubSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.21.12+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.20.11+0x0): multiple definition of `gsSubState'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.20.11+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.18.9+0x0): multiple definition of `gsSubSollTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.18.9+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.17.8+0x0): multiple definition of `gsPubSollTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.17.8+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.16.7+0x0): multiple definition of `gsPubTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.16.7+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.15.6+0x0): multiple definition of `gsPubTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.15.6+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.14.5+0x0): multiple definition of `mqttPass'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.14.5+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.13.4+0x0): multiple definition of `mqttUser'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.13.4+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.12.3+0x0): multiple definition of `mqttID'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.12.3+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.8.1+0x0): multiple definition of `passWord'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.8.1+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.irom.text.static.h.7.0+0x0): multiple definition of `SSID'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.7.0+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.msg+0x0): multiple definition of `msg'; .pio/build/esp12e/src/functions.cpp.o:(.bss.msg+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.runTimeIndex+0x0): multiple definition of `runTimeIndex'; .pio/build/esp12e/src/functions.cpp.o:(.bss.runTimeIndex+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.ptr+0x0): multiple definition of `ptr'; .pio/build/esp12e/src/functions.cpp.o:(.bss.ptr+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.l_gsIstTimeS+0x0): multiple definition of `l_gsIstTimeS'; .pio/build/esp12e/src/functions.cpp.o:(.bss.l_gsIstTimeS+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsIstTimeS+0x0): multiple definition of `a_gsIstTimeS'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsIstTimeS+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsIstTimeS+0x0): multiple definition of `gsIstTimeS'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsIstTimeS+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.l_gsIstTimeM+0x0): multiple definition of `l_gsIstTimeM'; .pio/build/esp12e/src/functions.cpp.o:(.bss.l_gsIstTimeM+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsIstTimeM+0x0): multiple definition of `a_gsIstTimeM'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsIstTimeM+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsIstTimeM+0x0): multiple definition of `gsIstTimeM'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsIstTimeM+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.l_gsIstTimeH+0x0): multiple definition of `l_gsIstTimeH'; .pio/build/esp12e/src/functions.cpp.o:(.bss.l_gsIstTimeH+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsIstTimeH+0x0): multiple definition of `a_gsIstTimeH'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsIstTimeH+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsIstTimeH+0x0): multiple definition of `gsIstTimeH'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsIstTimeH+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsSollTimeH+0x0): multiple definition of `a_gsSollTimeH'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsSollTimeH+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsSollTimeH+0x0): multiple definition of `gsSollTimeH'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsSollTimeH+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsIstTemp+0x0): multiple definition of `a_gsIstTemp'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsIstTemp+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.gsIstTemp+0x0): multiple definition of `gsIstTemp'; .pio/build/esp12e/src/functions.cpp.o:(.bss.gsIstTemp+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.bss.a_gsSollTemp+0x0): multiple definition of `a_gsSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.bss.a_gsSollTemp+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/main.cpp.o:(.data.gsSollTemp+0x0): multiple definition of `gsSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.data.gsSollTemp+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.22.13+0x0): multiple definition of `gsSubSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.22.13+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.21.12+0x0): multiple definition of `gsPubSollTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.21.12+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.20.11+0x0): multiple definition of `gsSubState'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.20.11+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.19.10+0x0): multiple definition of `gsPubState'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.19.10+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.18.9+0x0): multiple definition of `gsSubSollTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.18.9+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.17.8+0x0): multiple definition of `gsPubSollTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.17.8+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.16.7+0x0): multiple definition of `gsPubTime'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.16.7+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.15.6+0x0): multiple definition of `gsPubTemp'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.15.6+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.14.5+0x0): multiple definition of `mqttPass'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.14.5+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.13.4+0x0): multiple definition of `mqttUser'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.13.4+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.12.3+0x0): multiple definition of `mqttID'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.12.3+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.11.2+0x0): multiple definition of `mqttServer'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.11.2+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.8.1+0x0): multiple definition of `passWord'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.8.1+0x0): first defined here /Users/mk/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: .pio/build/esp12e/src/static.cpp.o:(.irom.text.static.h.7.0+0x0): multiple definition of `SSID'; .pio/build/esp12e/src/functions.cpp.o:(.irom.text.static.h.7.0+0x0): first defined here collect2: error: ld returned 1 exit status *** [.pio/build/esp12e/firmware.elf] Error 1
I read all the post to that problem, all my files are in the SRC directory,
My .h files have
#ifndef FILENAME_H
#define FILENAME_H
The error tells me there a some douple declarations, but I do not know how to fix.
I am on OS X Mojave latest patches and PlatformIO latest Version
My PlatformIO.ini

[env:esp12e]

monitor_speed = 115200

platform = espressif8266

board = esp12e

framework = arduino

lib_deps = knolleary/PubSubClient@^2.8

Thanks for help

Sorry, but how to mark code

Looks like you put the definition of a variable in header files and not only the declaration. This leads to a duplicate definition for every .cpp file which includes a certain header name. See e.g. Splitting cpp files - #2 by maxgerhardt.

Thank you that leads me in the right directions. Think I have to learn more about that