Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use ReactiveArduinoLib in two cpp files because of emitting code. Linker errors. #10

Open
rzeldent opened this issue Jan 17, 2023 · 2 comments

Comments

@rzeldent
Copy link

rzeldent commented Jan 17, 2023

When there are two cpp files present that include the ReactiveArduinoLib.h file, linking breaks.
This is probably caused because not all the definitions are templates but do generate code.
Looks like this is caused by the Serial Observables.
Project to reproduce in PlatformIO is attached.

Archive.zip

Linking .pio/build/esp32dev/firmware.elf
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<unsigned char>::Suscribe(IObserver<unsigned char>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:30: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:30: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<char>::Suscribe(IObserver<char>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:30: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:30: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<String>::Suscribe(IObserver<String>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:33: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:33: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<int>::Suscribe(IObserver<int>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:35: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:35: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<float>::Suscribe(IObserver<float>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:42: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:42: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<double>::Suscribe(IObserver<double>&)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:42: multiple definition of ObservableSerial::Suscribe(IObserver&)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:42: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<unsigned char>::ObservableSerial()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:25: multiple definition of ObservableSerial::ObservableSerial()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:25: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<unsigned char>::ObservableSerial()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:25: multiple definition of ObservableSerial::ObservableSerial()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:25: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<char>::ObservableSerial()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:25: multiple definition of ObservableSerial::ObservableSerial()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:25: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<char>::ObservableSerial()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:25: multiple definition of ObservableSerial::ObservableSerial()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:25: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<String>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:27: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:27: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<String>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:27: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:27: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<int>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:29: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:29: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<int>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:29: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:29: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<float>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:36: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:36: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<float>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:36: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:36: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<double>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:36: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:36: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<double>::ObservableSerial(char)': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:36: multiple definition of ObservableSerial::ObservableSerial(char)'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:36: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<unsigned char>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:35: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialByte.h:35: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<char>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:35: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialChar.h:35: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<String>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:38: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialString.h:38: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<int>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:40: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialInteger.h:40: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<float>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:47: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialFloat.h:47: first defined here
/pio/build/esp32dev/src/screen_connecting.cpp.o: in function ObservableSerial<double>::Receive()': ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:47: multiple definition of ObservableSerial::Receive()'; .pio/build/esp32dev/src/main.cpp.o:ibdeps/esp32dev/ReactiveArduino/src/Observables/ObservableSerialDouble.h:47: first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32dev/firmware.elf] Error 1

@rzeldent
Copy link
Author

Looks like there are some class functions in the ObserableSerial specialization classes that are missing the template<> before the implementations

@rzeldent
Copy link
Author

Is solved by using inline so they the functions are not emitted by the header files. Saves memory if not used and possibility to include the files multiple times. See PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant