Compile errors when including SoftwareSerial library

I am trying to build a simple sketch which includes the SoftwareSerial library.

#include <Arduino.h>

#include <SoftwareSerial.h>

#define RX 10
#define TX 11

SoftwareSerial esp8266(RX,TX);

I have a compile time error as follows

In file included from .piolibdeps/EspSoftwareSerial_ID168/src/SoftwareSerial.cpp:25:0:
.piolibdeps/EspSoftwareSerial_ID168/src/SoftwareSerial.h:29:22: fatal error: functional: No such file or directory

I searched for the header file and found I needed to also include the Embedded Template Library, which I did. This left the same initial compile time error but added a further one:

In file included from .piolibdeps/Embedded Template Library_ID930/src/binary.cpp:31:0:
.piolibdeps/Embedded Template Library_ID930/src/platform.h:49:25: fatal error: etl_profile.h: No such file or directory

My platformio.ini looks like this:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

; lib_ldf_mode = chain+

lib_deps =
  EspSoftwareSerial
  Embedded Template Library

Including the chain+ ldf mode does not fix the issue. Could someone help please?

Here are some more build logs:

Dependency Graph
|-- <EspSoftwareSerial> 5.0.4
|-- <Embedded Template Library> 10.21.2
Compiling .pioenvs/uno/src/main.cpp.o
Compiling .pioenvs/uno/src/sensor_reading.cpp.o
Compiling .pioenvs/uno/lib8af/EspSoftwareSerial_ID168/SoftwareSerial.cpp.o
Compiling .pioenvs/uno/lib0be/Embedded Template Library_ID930/binary.cpp.o

Maybe an issue lies in EspSoftwareSerial being compiled before Embedded Template Library?

Edit: Swapping the order (in platformio.ini) results in more ‘No such’ errors arising from the ETL compilation, such as ecl_user.h)

Some further debugging. I have removed the SoftwareSerial library and am trying to just compile the Embedded Template Library.

One issue is etl_profile.h not being found when included in platform.h. I can change the include path to `“profiles/etl_profile.h” which fixes the issue.

Another issue is then not being able to find ecl_user.h included in ecl_timer.h, but the only source of this file is within the examples folder.

Another issue is not being able to find limits included in binary.h. I know limits is part of the C++ STL. Trying to include the std lib through the build flags and trying to include the StandardCplusplus library through PlatformIO (separate attempts) resulted in compile errors.

Maybe this is an issue with my general C++ environment :frowning:

Would love some help

I have managed to solve (some) of these issues. The problem was mostly my lack of reading.

Firstly I removed the SoftwareSerial library and focused on successfully compiling the Embedded Template Library (ETL).

My platform is Arduino.

ETL requires a Standard Template Library (STL) for Arduino. I installed (via PlatformIO) the ArduinoSTL, and included this as my first libdep.

ETL setup requires some user configuration to get going, as described here: setup

Firstly an etl_profile.h file is required. I took the example file profiles/arduino_arm.h, and copied it into Embedded Template Library/src as etl_profile.h.

Secondly an ecl_user.h file is required. I took the example file found in Embedded Template Library/ArmTimerCallbacks - C/ecl_user.h and copied it into Embedded Template Library/src/c. I then made a small modification, changing the line

#define ECL_TIMER_TIMER_SEMAPHORE uint32_t

into

extern uint32_t timer_semaphore;

and then renaming the x variable as timer_semaphore.

I am not sure these adjustments are correct, however this results in the ETL successfully compiling.

I am now tackling the successful compilation of the SoftwareSerial library (and am dealing with an issue with the atomic include).

Though this thread is just a diary of my debugging, I hope anyone with a similar issue in future will find this useful.

Sorry to tell you this late, but the actual problem is as follows:

  • it uses a library it absolutely shouldn’t, because SoftwareSerial is built into the framework core at .platformio\packages\framework-arduinoespressif8266\libraries\SoftwareSerial. Uninstall it using pio lib uninstall 168

  • you must not name your variable esp8266 because it is the name of a namespace declared in framework-arduinoespressif8266\cores\esp8266\core_esp8266_version.h

This code works absolutely fine and you do not need to continue searching for ways to get the ETL library to run in order to satisfy the <functional> include of that lib.

#include <Arduino.h>
#include <SoftwareSerial.h>

#define RX 10
#define TX 11

SoftwareSerial softSerial1(RX,TX);

void setup(){
	Serial.begin(115200);
	softSerial1.begin(9600);
}

void loop() {
	if(softSerial1.available())
		Serial.write((char)softSerial1.read());
}

Compile log should look like this

CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz 80KB RAM (4MB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <EspSoftwareSerial> 3.4.1 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif8266\libraries\SoftwareSerial)
[..]
DATA:    [===       ]  33.2% (used 27216 bytes from 81920 bytes)
PROGRAM: [===       ]  25.4% (used 265696 bytes from 1044464 bytes)
 [SUCCESS] Took 4.95 seconds 

Thanks for the reply @maxgerhardt.

It seems with your help my project will be much cleaner. I’ve removed the ArduinoSTL and ETL libraries and now just have the EspSoftwareSerial lib at 5.0.4 (maybe I should downgrade to your 3.4.1).

And thanks for raising the naming issue, I may not have found that.

I still run into atomic not being found, included in SoftwareSerial.h:30:18.

My configuration and platform is directed at the Arduino Uno. The ESP8266 is just a peripheral to the board and its other components (sensors). Is it better to change this? What are the implications?

Still using some external library then and not the one in the framework folder. Go to your project folder, activate “show hidden files” (different from OS to OS) and remove the .piolibdeps folder and execute the clean target before compiling again. Did you remove the EspSoftwareSerial using the library manager? Either from inside VSCode or the commandline as I have shown.

If those libraries are the same and the framework just has an outdated version of it, you can still force PlatformIO to use the correct version by going into your project’s platformio.ini and stating

lib_deps = EspSoftwareSerial@3.4.1

Right, removed the external library (using the CLI) and the .piolibdeps folder and ran pio run -t clean.

I now have No such gpio.h on SoftwareSerial.cpp:27:18, on either 5.0.4 or 3.4.1. I ran a pio update just to make sure, but to no help.

Thanks a lot for the help.

Edit: Ah. It seems the gpio include comes from the Espressif SDK. So this is where my platform as the Uno comes into play. Can I include this SDK as a library and keep the Uno platform, or should I be changing platform?

Find your PlatformIO home folder (Windows: C:\Users\<user>.platformio, Linux/Mac /home/<user>/.platformio/) and remove the packages\framework-arduinoespressif8266 and platforms\espressif8266 folder. If it can’t find gpio.h something is really, really broken. When compiling again, PIO will automatically re-download the deleted folders.

I don’t have those folders. It must be because of my targeting the Uno and not the Esp8266.

platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

Could you advise as to the effect of changing this in terms of Arduino development?

Ok I infered you were working with esp8266 because it initally tried including that library. Let me see how it is for AVR.

Still works.

#include <Arduino.h>
#include <SoftwareSerial.h>

#define RX 10
#define TX 11

SoftwareSerial softSerial1(RX,TX);

void setup(){
	Serial.begin(115200);
	softSerial1.begin(9600);
}

void loop() {
	if(softSerial1.available())
		Serial.write((char)softSerial1.read());
}
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR > Arduino Uno
HARDWARE: ATMEGA328P 16MHz 2KB RAM (31.50KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 8 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SoftwareSerial> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoavr\libraries\__cores__\arduino\SoftwareSerial)
DATA:    [=         ]  14.7% (used 301 bytes from 2048 bytes)
PROGRAM: [=         ]   9.7% (used 3140 bytes from 32256 bytes)
 [SUCCESS] Took 2.54 seconds 

What error does come up when using no lib_deps directive and having removed the EspSoftwareSerial library?

Right. Interesting to see your dependency is SoftwareSerial. I ran another pio lib uninstall 168, and rebuilt the project. Here is the output.

CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR > Arduino Uno
HARDWARE: ATMEGA328P 16MHz 2KB RAM (31.50KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 8 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <EspSoftwareSerial> 5.0.4
|   |-- <ArduinoSTL> 1.1.0
Compiling .pioenvs/uno/src/main.cpp.o
Compiling .pioenvs/uno/src/sensor_reading.cpp.o
Compiling .pioenvs/uno/libb03/ArduinoSTL_ID750/ArduinoSTL.cpp.o
Compiling .pioenvs/uno/libb03/ArduinoSTL_ID750/abi/abi.cpp.o
In file included from src/main.cpp:2:0:
/Users/louis/.platformio/lib/EspSoftwareSerial_ID168/src/SoftwareSerial.h:30:18: fatal error: atomic: No such file or directory
compilation terminated.
*** [.pioenvs/uno/src/main.cpp.o] Error 1

platformio.ini is at its minimum:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

Even though I ran the uninstall, it’s using a /lib version of SoftwareSerial. Maybe I’ll manually delete this. Your use through /packages looks like what I want.

Also the .piolibdeps folder is empty? Maybe also pio lib uninstall ArduinoSTL or retry on a new clean project. Somehow the uninstall didn’t go through because its still in /Users/louis/.platformio/lib/EspSoftwareSerial_ID168/. Try maybe pio lib --global uninstall 168

2 Likes

Got it!

I manually deleted the contents of /.platformio/lib and at compilation the framework-arduinoavr version was instead chosen. Now my project successfully compiles, thanks very much :slight_smile:

1 Like

Very likely pio lib uninstall only removes libs from .piolibdeps or lib/ of the project it is executed in, but you installed the library in the global storage. So after removing that the build goes through, but global uninstall should have worked, too. Glad it’s working now.

1 Like