Fatal error: Wire.h: No such file or directory -- How fix?

Hello,
IDE is 1.8.19 on Win 7

I installed library Adafruit_GFX
and Adafruit SSD1306.
I used the example from: ..MyDocuments\Arduino\libraries\Adafruit_SSD1306\examples\ssd1306_128x64_i2c

It builds and loads fine. No issue.

I then copied the code from this example into my own newly created project.
I then get this error:
fatal error: Wire.h: No such file or directory.

But it appears that all my #includes are a problem, They look like this:

#include <Arduino.h>
#line 1 "C:\\Users\\Admin\\Documents\\Arduino\\TImer2_BD\\TImer2_BD.ino"
#include <stdio.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

The example has the exact same header files but that builds and loads no errors.
It looks like this:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

It doe NOT have #include <Arduino.h> and is does NOT have the #line1....
But removing those from my project does not fix the problem.

Is this some sort of path problem or something?

Can someone please let me know how to fix this?

I have exhausted my possibilities of getting it to work without help.

Best regards
berntd

What happens in that case? Post the error message.

Also post the complete code of the failing example, using code tags.

The output with the #line that you posted seems to be the output of the Arduino builder. Your ino file would usually not contain that line and most people also don't include the Arduino.h file.

I seem to remember that I have experienced problems when including Arduino.h in the ino file; I know it's not needed because the builder will include it for you.

I just got it to work!

This time, instead of starting a new project and pasting example code into it, I opened the example and then used 'save as' to make it mine.
Then I pasted my original code into this and it is building fine as far as the header files go.

The arduino.h was automatically added from somewhere.

The #line was originally not there but appeared at some stage after re-opening the IDE and project. I still have no idea what it means and I discovered more of those #line directives in other places of my code.

Ohhhh wait....
I just remembered:
My code was all lost because IDE 2.1.? never saved anything. It pretended to but did not. I lost a big chunk of work.
So I managed to recover all of it from some Arduino build folder as a .cpp file.
The #line stuff may have come from there,
Hmm.

It indeed does. That cpp file is what the builder creates.

You can mark your topic as solved by clicking the "solution" button under the most useful post. That way others know that it's solved.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.