Iostream and cstring not found on compilation for Arduino WiFi rev 2

I am using platformIo environment to buil my C++ code based on Arduino framwork. I have added

#include < iostream>
#include < fstream>

Whicle compilation this error message:
/E R R O R - M E S S A G E*******/
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio/build/uno_wifi_rev2/src/cust_libs/led.cpp.o
src/cust_libs/led.cpp:15:10: fatal error: iostream: No such file or directory
#include < iostream>
compilation terminated.
Compiling .pio/build/uno_wifi_rev2/src/cust_libs/mqtt.cpp.o
Compiling .pio/build/uno_wifi_rev2/src/cust_libs/wifi_ctrl.cpp.o
src/cust_libs/mqtt.cpp:15:10: fatal error: cstring: No such file or directory
#include < cstring>
compilation terminated.
Compiling .pio/build/uno_wifi_rev2/src/main.cpp.o
src/main.cpp:15:10: fatal error: iostream: No such file or directory
#include < iostream>
compilation terminated.
In file included from src/cust_libs/wifi_ctrl.cpp:15:0:
src/cust_libs/wifi_ctrl.h:16:10: fatal error: WiFi.h: No such file or directory

/M A I N . C P P*****/
#include < iostream>
#include < fstream>
#include “cust_libs/headers.h”
#include “cust_libs/mqtt.h”
#include “cust_libs/led.h”
#include “cust_libs/wifi_ctrl.h”

// Creation of the wifi/mqtt objects
Wifi* wifi = new Wifi();
Mqtt* mqtt = new Mqtt();

// This function ‘setup’ gets called only once i.e. It initializes the things.
// We can write code which would get executed only once here.
void setup() {
// Setting up the serial baud rate

// Starting an log file to keep the track
// std::ofstream* logFile = new std::ofstream();
// logFile->open(LOG_FILE_NAME, std::ios::out | std::ofstream::app);
// if(!logFile->is_open()) {
// Serial.println(“ERROR: FILE NOT OPENED.”);
// }

// Setting up the member variables for both wifi/mqtt class
// Reason why we don’t have one common filePtr is because we probably
// do not understand the Arduino infrastructure very well.
// Ideally, there should be only one filePtr which is shareable across
// all classes of this project.
// wifi->setLogFile(logFile);
// mqtt->setLogFile(logFile);

// Defines the directions of the pins specified
pinMode(mqtt->led->getSensorPin(), INPUT);
// *logFile << “Pin number " << mqtt->led->getSensorPin() <<
// " made as sensor input” << std::endl;
pinMode(mqtt->led->getLedPin(), OUTPUT);
// *logFile << “Pin number " << mqtt->led->getLedPin() <<
// " made as led input” << std::endl;

// Connects the esp32 board with the wifi
// TODO: Collect the return status of this and take action accordingly.
Serial.println(“Connecting with WIFi”);

Serial.println(“Setting up the mqtt clients”);
// Setting up the variables for making the esp32 board as an subscriber
// TODO: Collect the return status of this and take action accordingly.

// Connect the client to the broker
// Internally, it keeps trying till the time mqttClient is not connected
// to the broker
// mqtt->tryReconnectToBroker();

void loop() {
// Publish the data to broker

And what is the platformio.ini?

This is the platform.ini for my project. Just to inform: The same code getting compiled for espressif32 platform but not for atmelmegaavr.

default_envs = uno_wifi_rev2

; [env:esp32doit-devkit-v1]
; platform = espressif32
; board = esp32doit-devkit-v1
; framework = arduino
; monitor_speed = 115200
; lib_deps = knolleary/PubSubClient@^2.8  

platform = atmelmegaavr
board = uno_wifi_rev2
framework = arduino
lib_deps = 

build_flags = -std=c++14
build_unflags = -std=gnu++11

AVR toolchains are notorious for not supporting standard C++ library features. Would not suprirse me if there’s no std::cout etc. You might want to use GitHub - mike-matera/ArduinoSTL: An STL and iostream implementation based on uClibc++ that supports my CS-11M class. in the lib_deps here and #include <ArduinoSTL.h>.

1 Like

Thank for your reply. Let me try with the ArduinoSTL.h.

In fact I think I should transform myself to get adjusted to the exisitng AVR-G++/AVR-GCC supported libraries.