Function not declared in this scope

I am trying to move my existing Arduino Mega project to Platform IO/VSCode. when I try to build I get a function name mot declared in this scope error. The function definition is prior to the Setup section of the sketch so it should be global. The error does not occur when building the sketch in Arduino IDEx2.0.4. I have run out of things to try and resolve this.

Are you able to post your code here? And your platformio.ini file?

In case you are not aware, code can be posted between three back-tick characters:

```
Like This
```

Which makes it much easier to read, copy and paste, and also, some characters after a \ have a tendency to vanish when posted as plain text.

Cheers,
Norm.

I accidentally stumbled on the solution. while all my functions were defined globally. the there was a function call made to that function from one defined earlier in the sketch. the Arduino IDE seems not to care if a function is defined before it is called.

1 Like

Good catch.

The Arduino IDE doesn’t care where your functions are defined. It runs a test compile, dumps the output to the null device and grabs the errors and uses that to add all the required function declarations to the top of the main ino file. It also works out which header files are required and adds them in too.

Cheers,
Norm.

1 Like