undefined reference to `WT2003S<SoftwareSerial>::init(SoftwareSerial&)'

Hello,

I'm just startet to playing around with aduino stuff and now have a problem with the usage of the SoftwareSerial library under my Digistump OAK Board.

My goal is to connect a mp3 player grove board from seeed (Grove - MP3 v3.0 | Seeed Studio Wiki) to my OAK using the SoftwareSerial library.

I must use the SoftwareSerial because the hardware serial port of the board is blocked for programming.
Please correct me, if I'm wrong.

This is the code I made:

#include <Arduino.h>
#include "WT2003S_Player.h"

#include <SoftwareSerial.h>
SoftwareSerial SSerial(5, 6);
#define COMSerial SSerial

WT2003S<SoftwareSerial> Mp3Player;

void setup(void) {
  COMSerial.begin(9600);
  Mp3Player.init(COMSerial);
  Mp3Player.playSDSong("processing.mp3");
}

void loop(void) {
}

And this is the error I get during compiling:

Mehrere Bibliotheken wurden für "SoftwareSerial.h" gefunden
 Benutzt: /Users/alex/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/SoftwareSerial
 Nicht benutzt: /Users/alex/Documents/Arduino/libraries/EspSoftwareSerial
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o:(.text.setup+0x10): undefined reference to `WT2003S<SoftwareSerial>::init(SoftwareSerial&)'
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o:(.text.setup+0x14): undefined reference to `WT2003S<SoftwareSerial>::playSDSong(char const*)'
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o: in function `setup':
/Users/alex/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/SoftwareSerial/src/SoftwareSerial.h:120: undefined reference to `WT2003S<SoftwareSerial>::init(SoftwareSerial&)'
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o: in function `setup':
/Users/alex/Documents/Arduino/R2D2_OAK/R2D2_OAK.ino:10: undefined reference to `WT2003S<SoftwareSerial>::playSDSong(char const*)'
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o: in function `_GLOBAL__sub_D_SSerial':
/Users/alex/Documents/Arduino/R2D2_OAK/R2D2_OAK.ino:15: undefined reference to `WT2003S<SoftwareSerial>::WT2003S()'
/Users/alex/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /var/folders/1l/w3mmn3s11230v1k3kn031qgc0000gn/T/arduino_build_854413/sketch/R2D2_OAK.ino.cpp.o: in function `_GLOBAL__sub_I_SSerial':
/Users/alex/Documents/Arduino/R2D2_OAK/R2D2_OAK.ino:4: undefined reference to `WT2003S<SoftwareSerial>::WT2003S()'
collect2: error: ld returned 1 exit status
Bibliothek Seeed_Serial_MP3_Player-master in Version 2.0.0 im Ordner: /Users/alex/Documents/Arduino/libraries/Seeed_Serial_MP3_Player-master  wird verwendet
Bibliothek SoftwareSerial in Version 6.4.0 im Ordner: /Users/alex/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/SoftwareSerial  wird verwendet
exit status 1
Fehler beim Kompilieren für das Board Digistump Oak.

If I use the same code for an arduino uno board it works without any issues.

Probably need to mess around with the end of the library file so that this

 #ifdef __AVR__
    #include <SoftwareSerial.h>
    template class WT2003S<SoftwareSerial>;
#endif

does not happen only for AVR but also for whatever is in your Digistump Oak.

Thank you for answering :slight_smile:

Unfortunately I'm really a noop in this kind of things.

May you can give me some more hints how to do this?

How can I change anything in this library?

Where is this AVR comes from?

How can I detect that it is my OAK board?

Questions over questions ...

when you select your board in the IDE, it sets some flags for the compiler that will define the target platform. Those flags can be used in your code to selectively add code for a given platform.

here for example they do

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    template class WT2003S<Uart>;
#endif
template class WT2003S<HardwareSerial>;

#ifdef __AVR__
    #include <SoftwareSerial.h>
    template class WT2003S<SoftwareSerial>;
#endif

that means if the Arduino you are compiling for has the flag "ARDUINO_SAMD_VARIANT_COMPLIANCE" set, then it will use Uart as part of the template. HardwareSerial is always instantiated but Software Serial is only instantiated if you are targeting an AVR based Arduino.
==> you want to use Software Serial but you likely don't have and AVR based architecture (I don't know that board) so the

    #include <SoftwareSerial.h>
    template class WT2003S<SoftwareSerial>;

does not happen when you compile for the Digistump Oak whereas it is included when you compile for your Arduino Uno (hence why it's working there).

two options:

the clean way:
you find out what distinctive flag is used for the "Digistump Oak" and you modify the lines at the end of the library to include a check for either the AVR or the DIGISTUMP_OAK

#if defined(__AVR__ ) || defined(DIGISTUMP_OAK)
    #include <SoftwareSerial.h>
    template class WT2003S<SoftwareSerial>;
#endif

I made up the DIGISTUMP_OAK flag though, so you need to find out what it is (seems based out of ESP8266)

the cheap and dirty way: :slight_smile:
You make a copy of the library source code in your sketch folder, and change the very end of the file to force the definitions.

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    template class WT2003S<Uart>;
#endif
template class WT2003S<HardwareSerial>;
#include <SoftwareSerial.h>
template class WT2003S<SoftwareSerial>;

As you do#include "WT2003S_Player.h" at the beginning of your code (with double quotes not <>) you are instructing the compiler to look first in the sketch folder for the library, before looking in the standard place.

Wow!

Thank you for this very helpful answer!

I tried the "dirty" way first and instantly get rid of the compiling error.

Unfortunately the SoftSerial is still not working :cry:

But now I get at least further.

Thanks again

OK - I don't know that architecture, so I'm unsure if the SoftwareSerial library that you get is compatible