Library impossible to include from two cpp files
maxgerhardt opened this issue · comments
Maximilian Gerhardt commented
See topic.
Due to the Encoder.h
class inlining the implementation, two files using the Encoder
after doig #include <EncoderTool.h>
will result in a double definition error.
Minimal reproduction with PlatformIO:
platformio.ini
[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_deps = https://github.com/luni64/EncoderTool.git
with src/main.cpp
#include <Arduino.h>
#include <EncoderTool.h>
using namespace EncoderTool;
Encoder enc1;
extern Encoder enc2;
void setup() {
enc1.begin(1, 2);
enc2.begin(3, 4);
}
void loop() {}
and src/helper.cpp
#include <Arduino.h>
#include <EncoderTool.h>
using namespace EncoderTool;
Encoder enc2;
void some_func() { }
leads to
.pio\build\teensy41\src\main.cpp.o: In function `EncoderTool::Encoder::Encoder()':
main.cpp:(.text._ZN11EncoderTool7EncoderC2Ev+0x0): multiple definition of `EncoderTool::Encoder::Encoder()'
.pio\build\teensy41\src\helper.cpp.o:helper.cpp:(.text._ZN11EncoderTool7EncoderC2Ev+0x0): first defined here
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/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\main.cpp.o: In function `EncoderTool::Encoder::Encoder()':
main.cpp:(.text._ZN11EncoderTool7EncoderC2Ev+0x0): multiple definition of `EncoderTool::Encoder::Encoder()'
.pio\build\teensy41\src\helper.cpp.o:helper.cpp:(.text._ZN11EncoderTool7EncoderC2Ev+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Maximilian Gerhardt commented
maxgerhardt@88d7f36 would solve this issue but get rid of the inline
definitions.
luni64 commented
fixed in v3.0.3