Fix/inline begin function #105
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Report: Multiple definition of
BLEMIDI_ESP32::beginwhen using with ESPAsyncWebServerDescription:
When using the
lathoub/BLE-MIDIlibrary in a PlatformIO project withESPAsyncWebServer, a "multiple definition" linker error occurs for theBLEMIDI_ESP32::beginfunction. This is because the function is defined in the header filehardware/BLEMIDI_ESP32.h, and this header is included in multiple source files.Test and logs at
ble-midi-repro.zip
To Reproduce:
esp32doit-devkit-v1board.platformio.ini:lib_deps = lathoub/BLE-MIDI me-no-dev/ESPAsyncWebServer me-no-dev/AsyncTCP fortyseveneffects/MIDI Library@^5.0.2main.cppfile with the following content:other.cppwith the following content:/app/ble-midi-repro/.pio/libdeps/esp32doit-devkit-v1/BLE-MIDI/src/hardware/BLEMIDI_ESP32.h:125: multiple definition of `bleMidi::BLEMIDI_ESP32::begin(char const*, bleMidi::BLEMIDI_Transport<bleMidi::BLEMIDI_ESP32, bleMidi::DefaultSettings>*)';
.pio/build/esp32doit-devkit-v1/src/main.cpp.o:/app/ble-midi-repro/.pio/libdeps/esp32doit-devkit-v1/BLE-MIDI/src/hardware/BLEMIDI_ESP32.h:125: first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32doit-devkit-v1/firmware.elf] Error 1
```
Fix:
The fix is to declare the
BLEMIDI_ESP32::beginfunction asinlineinhardware/BLEMIDI_ESP32.h. This allows the compiler to resolve the multiple definitions at link time.Change: