Sorry to have to ask, but can not find solotion
I have on Project with esp32doit-devkit-v1 and marcoschwartz/LiquidCrystal_I2C@^1.1.4 for LCD display
Compiles fine run fin as expected
I have a second project, same board compiles fine runs as expected, now I added the same display as above, added just the setup, included same librarys, added the lines from project one, but now I get an compile error
The version without display still compiles and works fine
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32doit-devkit-v1/firmware.elf] Error 1
can not find a reason, any help/hint to find the problem
Thank you
Regards
Rainer
Building in release mode
Linking .pio/build/esp32doit-devkit-v1/firmware.elf
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:22: multiple definition of `PARAM_DRY_0'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:22: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:23: multiple definition of `PARAM_WET_0'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:23: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:24: multiple definition of `PARAM_DRY_1'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:24: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:25: multiple definition of `PARAM_WET_1'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:25: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:26: multiple definition of `PARAM_DRY_2'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:26: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:27: multiple definition of `PARAM_WET_2'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:27: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:28: multiple definition of `PARAM_DRY_3'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:28: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:29: multiple definition of `PARAM_WET_3'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:29: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:30: multiple definition of `PARAM_DRY_4'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:30: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:31: multiple definition of `PARAM_WET_4'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:31: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:32: multiple definition of `PARAM_DRY_5'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:32: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:33: multiple definition of `PARAM_WET_5'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:33: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:7: multiple definition of `local_IP'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:7: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:9: multiple definition of `gateway'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:9: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:11: multiple definition of `subnet'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:11: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:12: multiple definition of `primaryDNS'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:12: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:13: multiple definition of `secondaryDNS'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:13: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:4: multiple definition of `ssid'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:4: first defined here
/Users/mk/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:5: multiple definition of `password'; .pio/build/esp32doit-devkit-v1/src/lcdstuff_32.cpp.o:/Users/mk/Documents/PlatformIO/Projects/Bakon_Water/src/main.h:5: first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32doit-devkit-v1/firmware.elf] Error 1
It looks like you have definitions in your main.h (not just declarations!) and you are including the main.h in different files. This will result in the multiple definitions error you receive.
If you want to have global variables you have to mark them as extern and put the definition into a .cpp file.
Example:
globals.h:
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
// declaration of PARAM_DRY_0
extern int PARAM_DRY_0;
#endif // _GLOBALS_H_
globals.cpp:
#include "globals.h"
// definition of PARAM_DRY_0
int PARAM_DRY_0 = 0;
Now you can include globals.h into multiple .cpp files without having this error
The header is included a maximum of once per translation unit (.c/.cpp) file. If the header creates a global variable instead of declaring the existance of a global variable, then each translation unit will create another instance of that global variable and you get a nice little explosion at the final linking stage (see your log). Thus, multiple definitions.
#ifndef MAIN_H
#define MAIN_H
// Definition. makes KABOOM if more than one .c/.cpp file includes this header
int my_global_var;
#endif
vs
#ifndef MAIN_H
#define MAIN_H
// existance declaration. Definition done in **one** separate .cpp file.
extern int my_global_var;
#endif
With the extern method, it doesn’t matter how many .c/.cpp files include the header, so I would still recommend you to switch to that. It’s the proper programming style to not create (=define) global variables inside a header file. Only declarations.