Blank lines inserted at start of sketch causes library errors

I have a strange (to me anyway) problem which I will do my best to explain. I have a sketch with some comments at the start that take up a few lines, followed by 5 library #includes. All worked OK with no compilation errors. Then I added more text lines to the comments which resulted in a compilation error.

Investigating further, the error appears only when a "certain" number of lines are inserted before the start of the first #include.

I resaved the sketch with 8 blank lines (which previously gave an error). When I reloaded it again later, it worked...until I deleted 1,2,3, 0r 4 lines, when it again gave the following error:-

C:\Users\Hp\Desktop\Test\Test.ino:9:10: fatal error: Adafruit_GFX.h: No such file or directory
#include <Wire.h> //IDE Standard
^~~~~~~~~~~~~~~~
compilation terminated.
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
-> candidates: [Wire@1.0]
exit status 1

Compilation error: Adafruit_GFX.h: No such file or directory

I notice that it throws up a compilation error for whatever library is on line 9 (apart from <wire.h>). The other 4 libraries were installed directly from their zip files. Once I add or remove lines which take line 9 above or below the libraries, the sketch works fine.

I can post the sketch & verbose error message if needed, but before doing that, I wondered if anyone else had encountered this or has an idea what causes it? I can't think it can be a common problem obviously, as it seems so weird.

I'm using IDE 2.3.2, Arduino Uno, Windows 10 Pro 64bit.

Post the original.

It is most likely a typo, you either have an open comment block or some other trivial error. DELETE all the comments, so that the first include is on line 1 and try again. Make sure the #includes do NOT end in ;

This issue has been reported before. I suggest that you search the IDE 2.x section of the forum.

Search results for 'empty line': Search results for '#software:ide-2-x empty lines' - Arduino Forum

@sterretje There's a thread by mol13 with the same problem as mine, but it resolved itself before a reason could be found:-

1 Like

@sonofcy Before I saved the sketch, I deleted all the lines above the first #include, so the first #include was the first line. The sketch compiled OK. I then added 8 blank lines at the top by pressing enter on keyboard. I saved the sketch. Closed it. Reopened it. It compiled OK. I deleted one of those 8 lines & got a compilation error. None of the #includes end in ; nor any other character.

@xfpd I'll post up the sketch in a little while.

Just for info, I have all the settings on default, except for Auto save. I prefer to be in control of when & how my sketches are saved.

If you can get the sketch in that state again, post just the first 10 lines BUT do NOT use the code method. zip the file first (just 10 lines) and attach that. I want to use a hex editor to see if you are somehow inserting a non-printable char.
Since you are the only person having this error, it is something in your environment. Perhaps your editor is leaving behind an 0x08 character and the hex view will show that.

Try with versión 1.8. it is clearly a bug in my opinion.

1 Like

@sonofcy I've copied & pasted the first 10 lines into notepad & zipped that. That was the only way I could think of doing it.

I have the same IDE build on my laptop. Exactly the same thing happens with that. The laptop also has Windows 10Pro.

I'll post the full sketch a bit later.

Edit...for info, the sketch works with 8 blank lines once it's saved. It's when one of the lines is deleted that the compilation error returns.

first_10_lines.zip (287 Bytes)

@mol13 The fact that it happens on 2 of my machines & it once happened to you, I think there's an elusive bug too. Did you also have Auto save turned off?

Yes. I don't like autos ave. I returned to v1.8 and the same source code didn't fail.

1 Like

I just tried what you said in post#6 and there was no error.
I think what is happening is your editor OR line deletion keystrokes are different from mine. I am suspicious you are leaving behind an unprintable char, most likely an 0x08 Back Space.
Using Notepad WILL change line ending chars. Just make a copy of the failing ino file, then delete all lines from just after the #includes to the end. Save it and zip it to here.

I've attached a zipped file of the .ino edited down to the first 14 lines. When trying to compile, it will of course complain that there's no void or loop. If I delete any of the lines, however, it will then give an error as in my first post (but for <Rotary.h> on line 10 this time).

Test_1_edited.zip (363 Bytes)

Hi @sonofcy, I looked for a non printable character with Hex Editor the first time, and it was not the case. In addition, if you put intentionally one of them, the compiler show a different error or simply ignored it.
I think I wrote a "bell" and a "hard space" (last one is a típical error when you convert a pdf to docx).
It is as simple as to have a compilated code and press Enter at the end of a line or just delete a blank line, and the error appears.
The code with apparent error compiles good in v1.8.

1 Like

Very weird. I had no problems with your sample. If it isn't a non-printable char as you have proven, then it is something in your environment.
If you know how to compile clean, I wouldn't waste any more time on it. Good luck.

@sonofcy Do you have Auto save disabled? (it's enabled by default). That's the only thing I have changed on my 2 installations. I ask because when I save a previously failing sketch, it then works. For example, the sketch I attached with 8 blank lines would refuse to compile if I deleted one line. But once I saved it, it would then work with 7 blank lines.

So yes, it can be worked around, but it's still an odd problem. As a new Arduino user, it had me tearing my hair out when it first happened as those first few lines were used for comments about the sketch. My first thought was that it was finger trouble. I deleted all the libraries, tried installing them in different way, & eventually uninstalled & reinstalled the IDE.

Yes I have autosave disabled because my sketches are automatically backed up to the cloud whenever they are saved.

Why will you not post the code, but will talk about it all day?
Does the same problem occur with other sketches?

@xfpd After sonofcy asked me to post just the begining of my sketch (as I did in post #14), it proved that it had nothing to do with the whole sketch, as the compilation error still occured with just the first 14 lines. That's why I didnt post the whole sketch.

To see if it happened with other sketches, I looked at a sketch in the examples in the Arduino IDE. I chose TFT > Arduino > TFTBitmapLogo. It uses 3 libraries on lines 23,24,25. It compiled OK as it was. But if I add just one more line at the top of the sketch, I get a compilation error where the first of the 3 libraries is highlighted:-

C:\Users\Hp\AppData\Local\Temp.arduinoIDE-unsaved2024621-6900-1uj54nc.ru0th\TFTBitmapLogo\TFTBitmapLogo.ino:24:10: fatal error: SPI.h: No such file or directory

  • #include <SD.h>*
  •      ^~~~~~ *
    

compilation terminated.
exit status 1

Compilation error: SPI.h: No such file or directory

I also get a compilation error if I add another line, or if I delete 1 or 2 lines. A different library is highlighted depending on the number of lines added/removed.

So anyone can try to simulate my problem.

In summary, if the first of those 3 libraries starts on line 21,22,24, or 25 then it throws up an error.

1 Like