blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.83k stars 1.38k forks source link

Multiple definition error(s) using platformio #416

Closed treii28 closed 6 years ago

treii28 commented 6 years ago

Blynk library version: [...] 0.5.3

IDE: [Arduino/Energia/MBED Compiler/Platform.IO/Eclipse ...] Platform.IO

IDE version: [...] 3.5.3

Board type: [...] esp32dev

Scenario, steps to reproduce

init new project using: > pio init --board esp32dev --ide clion

modified Esp32 SSL example to include Arduino.h, renamed to src/main.cpp

Execute 'run' to compile firmware: > pio run

[What you are trying to achieve and you can't?] compile firmware

Expected Result

Success

Actual Result

Series of 'multiple definition' errors

> pio run
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
[Tue Jun 12 12:23:07 2018] Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
--------------------------------------------------------------------------------
/usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
warnings.warn(warning, RequestsDependencyWarning)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 > Espressif ESP32 Dev Module
SYSTEM: ESP32 240MHz 288KB RAM (1.25MB Flash)
DEBUG: CURRENT(minimodule) EXTERNAL(minimodule, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h)
Converting ESP32_WiFi_SSL.ino
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Blynk> v0.5.3
|   |-- <WiFiClientSecure> v1.0
|   |   |-- <WiFi> v1.0
|   |-- <WiFi> v1.0
|-- <WiFi> v1.0
|-- <WiFiClientSecure> v1.0
|   |-- <WiFi> v1.0
Compiling .pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o
Compiling .pioenvs/esp32dev/lib712/Blynk_ID415/utility/BlynkDebug.cpp.o
Compiling .pioenvs/esp32dev/lib712/Blynk_ID415/utility/BlynkHandlers.cpp.o
Compiling .pioenvs/esp32dev/lib712/Blynk_ID415/utility/BlynkTimer.cpp.o
Compiling .pioenvs/esp32dev/lib712/Blynk_ID415/utility/utility.cpp.o
Archiving .pioenvs/esp32dev/lib712/libBlynk_ID415.a
Indexing .pioenvs/esp32dev/lib712/libBlynk_ID415.a
Linking .pioenvs/esp32dev/firmware.elf
.pioenvs/esp32dev/src/main.cpp.o: In function `blynk_dbg_print(char const*, ...)':
main.cpp:(.text._Z15blynk_dbg_printPKcz+0x0): multiple definition of `blynk_dbg_print(char const*, ...)'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:ESP32_WiFi_SSL.ino.cpp:(.text._Z15blynk_dbg_printPKcz+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o:(.data.pass+0x0): multiple definition of `pass'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:(.data.pass+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o:(.data.ssid+0x0): multiple definition of `ssid'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:(.data.ssid+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o:(.bss.Blynk+0x0): multiple definition of `Blynk'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:(.bss.Blynk+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o:(.data.auth+0x0): multiple definition of `auth'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:(.data.auth+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o: In function `setup()':
main.cpp:(.text._Z5setupv+0x0): multiple definition of `setup()'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:ESP32_WiFi_SSL.ino.cpp:(.text._Z5setupv+0x0): first defined here
.pioenvs/esp32dev/src/main.cpp.o: In function `loop()':
main.cpp:(.text._Z4loopv+0x0): multiple definition of `loop()'
.pioenvs/esp32dev/src/ESP32_WiFi_SSL.ino.cpp.o:ESP32_WiFi_SSL.ino.cpp:(.text._Z4loopv+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pioenvs/esp32dev/firmware.elf] Error 1
========================== [ERROR] Took 3.83 seconds ==========================

Generally when I have run into this, it can be gotten around by wrapping the various 'Include' lines with compiler directives to check first if the library has already been included by the platformio compiler. e.g. when I add the arduino header in main.cpp I do it as:

#ifndef Arduino_h
#include <Arduino.h>
#endif

Similarly if I get a source package set up for the Arduino IDE that isn't optimized for other compiling methods, if I go into the header files for the package and similarly add the symbols defined for each in a simlar ifndef test surrounding all #include lines, I no longer get attempts to re-define constants or functions.

So, for example, in the SSL example code where it includes it's needed libraries I modify those includes as follows:

#ifndef WiFi_h
#include <WiFi.h>
#endif
#ifndef WiFiClientSecure_h
#include <WiFiClientSecure.h>
#endif
#ifndef BlynkSimpleEsp32_SSL_h
#include <BlynkSimpleEsp32_SSL.h>
#endif

If I still get the errors, I then similarly modify the headers in the library themselves until the errors cease.

vshymanskyy commented 6 years ago

@treii28 will take a look soon

treii28 commented 6 years ago

@vshymanskyy Grrr, nevermind. It was my mistake. I had initially copied the ino file and I usually rename it to the main.cpp before compiling but apparently just copied it this time so the ino was still in the directory. stupid stupid stupid