How to fix: 'function' was not declared in this scope

So i head about this new fancy IDE called Platform.io. So i decided to give it a spin and imported my Arduino Code into n new Project, installed all Libraries and tried to compile and upload it. I managed to get the blink example compiled and uploaded to the ESP32. But my other code need a complete rewrite, as many functions are declared at the wrong time.
In the Arduino IDE there is no problem if i call a function first and than declare it later in a utils/functions block. But with WSC and Platformio, this code does not compile and throws many errors like this:

This is due to the fact that the Arduino IDE interpretes the sketches as .ino files and does pre-processing on them, which pre-declares all known function prototypes.

The FAQ shows you how to rewrite .ino files in proper .cpp files.

PIO also supports the same preprocessing by renaming your main.cpp file simply to main.ino. But then you lose the VSCode Intellisense because that plugin cannot work with Arduino INO files. So, conversion is recommended if you want to properly develop the project. For a quick compilation-and-upload without further developing it, just go the .ino path.

Thanks for the link to the rewrite FAQ! Gues i have to learn proper C++ now :sweat_smile:

Can you also give me a link for how to package a library from github for the esp-idf (Espressif IoT Development Framework)?

A library in ESP-IDF is usually implemented as a “component”. Again see documentation and example project which includes the esp-aws-iot component / “library”.

1 Like

I am struggling with a project which I have many “function’ was not declared in this scope” erros that did not appears in the Arduino IDE.

‘SerialUSB’ was not declared in this scope
‘Serial’ was not declared in this scope
cannot open source file “WiFiS3.h”
identifier “INPUT” is undefined
identifier “pinMode” is undefined

And most of these libraries I am unable to even find.

I am sure I must be missing something basic.

Any ideas?

What’s your platformio.ini ?

You have probably just forgotten #include <Arduino.h>