Undefined reference to `SoftwareSerial::SoftwareSerial(Unsigned char, Unsigned char, bool)`

If you are asking a question, please follow this template:

  1. My goal is: to create a C++ wrapper for mgos_mhz19_begin() {}
  2. My actions are: in my deps/mhz19/src/mgos_mhz19.cpp I created a wrapper for MHZ19
  • here’s my code in deps/mhz19/src/mgos_mhz19.cpp
#include <HardwareSerial.h>
#include <SoftwareSerial.h>

MHZ19 *mgos_mhz19_create() {
  return new MHZ19();
}

void mgos_mhz19_begin(MHZ19 *mhz) {
  if (mhz == nullptr) return;
  int RX_PIN = 10 ;
  int TX_PIN = 11;
  SoftwareSerial mySerial(RX_PIN, TX_PIN);
  int BAUDRATE = 9600; 
  mySerial.begin(BAUDRATE);
  return mhz->begin(mySerial);
}

void mgos_mhz19_close(MHZ19 *mhz) {
  if (mhz != nullptr) {
    delete mhz;
    mhz = nullptr;
  }
}

int mgos_mhz19_getCO2(MHZ19 *mhz) {
    if (mhz == nullptr) return MGOS_MHZ19_RES_FAIL;
    return mhz->getCO2();
}
  1. The result I see is: when I build the app I got this error
  AR    /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/mongoose-os.a
  CC    /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/gen/mg_build_info.c
  GEN   /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/gen/build_info.c
  CC    /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/gen/build_info.c
  LD    /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/zip-iot-virus-index-nodemcu.elf
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/mgos_mhz19.cpp.o:(.text.mgos_mhz19_begin+0x4): undefined reference to `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)'
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/mgos_mhz19.cpp.o:(.text.mgos_mhz19_begin+0x8): undefined reference to `SoftwareSerial::begin(long)'
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/mgos_mhz19.cpp.o:(.text.mgos_mhz19_begin+0xc): undefined reference to `SoftwareSerial::~SoftwareSerial()'
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/mgos_mhz19.cpp.o: in function `mgos_mhz19_begin':
/data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/deps/mhz19/src/mgos_mhz19.cpp:13: undefined reference to `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)'
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/deps/mhz19/src/mgos_mhz19.cpp:15: undefined reference to `SoftwareSerial::begin(long)'
/opt/Espressif/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/9.2.0/../../../../xtensa-lx106-elf/bin/ld: /data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/deps/mhz19/src/mgos_mhz19.cpp:16: undefined reference to `SoftwareSerial::~SoftwareSerial()'
collect2: error: ld returned 1 exit status
/data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/deps/modules/mongoose-os/platforms/esp8266/Makefile.build:358: recipe for target '/data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/zip-iot-virus-index-nodemcu.elf' failed
make: *** [/data/fwbuild-volumes/2.18.0/apps/zip-iot-virus-index-nodemcu/esp8266/build_contexts/build_ctx_109490104/build/objs/zip-iot-virus-index-nodemcu.elf] Error 1
make: Leaving directory '/app'
Error: exit status 2
/src/cli/build_local.go:697: 
/src/cli/build_local.go:684: 
/src/cli/build_local.go:449: 
/src/cli/build.go:270: 
/src/cli/build.go:213: 
/src/cli/main.go:198: build failed
Error: /src/cli/build_remote.go:333: build failed
/src/cli/build.go:270: 
/src/cli/build.go:213: 
/src/cli/main.go:198: build failed
  1. My expectation & question is: What is software serial for?

It looks like you are trying to port an Arduino library.
There is no SoftwareSerial in Mongoose OS.

1 Like

Ah yeah that’s exactly what I’m doing. because were trying to port an MHZ19 co2 arduino library to mongoose os and actually I’m really confused now.