Hi all, today I noted that if I add a New Line (intro) in my source code, before #includes, IDE returns a compilation error saying that:
fatal error: OneWire.h: No such file or directory #include <DallasTemperature.h>
^~~~~~~~~~~
compilation terminated.
In this case, OneWire.h is the second in my #include list at line 47, DallasTemperature is at line 48, but if I add a two New Lines, the compilation error is about other library.
This issue doesn,t happen with IDE 1.8.
Obviously my code in 2.1 compiles OK and i have all the libraries that i need in the correct folder.
I just can´t edit my code because of this error.
Hi sterretje, my program is working OK and compile OK until I write a new line before the #includes.
Nevermind if it's a code line or a blank line, it seems like IDE detects my #includes in a different row in relation with the no edited code.
Example:
I have #include <OneWire.h> at line 45 of my sketch.
So, if i put the cursor at the begin of row 45 and push intro on my keyboard, my row 45 is placed at row 46 and row 45 is now an empty line (super basic).
In this moment if i push Verify, IDE returns that errors, and if i push backspace and clear the empty row 45, the code is compiled OK again.
But, if i add a new empty line or code line, after de #includes, it compiles OK.
I suspect it's a bug.
My code has thousand of lines, i can't upload.
I'm sorry. A video would be better, i think.
Thank you.
Please produce a minimal demonstration of the bug. This "minimal, reproducible, verifiable example" (MCVE) will make it easier for us to investigate the issue and be useful when submitting a bug report to the developers anyway.
For example, does the "No such file or directory" compilation error occur if you attempt to compile this code (note that I added an empty line before the #include directive)?:
I understand the problem you are having. But we need to be able to reproduce it in order to do anything about fixing it.
So you need to provide us with a sketch we can use to reproduce it. If you aren't willing to share your full sketch, then produce a minimal sketch that produces the same behavior.
Well, I was working on it and I could generate a reasonable MCVE.
Pay attention to commented line numbers, to sum up, it seems like: #include <avr/wdt.h> // Line 50 , can not be in Line 51 or greater.
In the real sketch, all lines from 1 to 48 has some texts like comments or #defines.
This is the MCVE:
// Line 1
// Line 10
// Line 20
// Line 30
// Line 40
// Line 41
// Line 42
// Line 43
// Line 44
// Line 45
// Line 46
// Line 47
// Line 48
// Line 49 TRY NEWLINE HERE
#include <avr/wdt.h> // Line 50
#include <OneWire.h>
#include <DallasTemperature.h>
#include <MFRC522.h>
#include <SPI.h>
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoMatrix.h>
#include <string.h> //Line 58
void setup()
{
}
void loop()
{ }
But ! if you move down all the includes 8 lines, "#include <avr/wdt.h> // Line 50" to line 58, the sketch compiles again.
Nice work on producing such a minimal MCVE! Unfortunately I still wasn't able to reproduce the fault even with the MCVE you provided. But since you are able to reproduce the fault at least, I can proceed with the investigation with your assistance.
I'm going to ask you to post the full verbose output from a compilation.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
Select File > Preferences... from the Arduino IDE menus.
The "Preferences" dialog will open.
Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
Click the OK button.
Put the sketch code into the configuration that produces the spurious compilation error.
Select Sketch > Verify/Compile from the Arduino IDE menus.
Wait for the compilation to fail.
You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the COPY ERROR MESSAGES button on that notification.
Open a forum reply here by clicking the Reply button.
Click the <CODE/> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
Click the Reply button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
Open a forum reply here by clicking the Reply button.
Click the "Upload" icon () on the post composer toolbar:
A dialog will open.
In the dialog, select the .txt file you saved.
Click the Open button.
Click the Reply button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
Ok, thanks. I know about verbose output and i will publish it ASAP.
Do you confirm that the error doesn't happen in your IDE ?
If you insert a new line before line 50, it compiles ok?
The MCVE I provided compiles OK in my IDE.
That is correct. I added the new line before line 50, compiled for the "Arduino Mega or Mega 2560" board, and the compilation was successful.
Thanks for the output.
At the start of compilation, the Arduino build system makes some small changes to your .ino files to convert them to valid C++. This process is known as "sketch pre-processing".
In some rare cases, the build system makes a mistake during the "sketch pre-processing" operation. This can lead to very confusing errors because the code causing the error is not present in your .ino file. For this reason, we must examine the code that was generated by the build system through the "sketch pre-processing" operation. This code is saved in the temporary folder shown in the compilation commands in verbose output. I'm going to ask you to post that code in a reply here:
Open the file at the following path in any text editor:
If looking for it with your file manager or command line, note that the AppDate folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".
Select all the text in the text editor.
Press Ctrl+C.
This will copy the selected text to the clipboard.
Open a forum reply here by clicking the Reply button.
Click the <CODE/> icon on the post composer toolbar. This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the copied text into the code block.
Move the cursor outside of the code block markup before you add any additional text to your reply.
#include <Arduino.h>
#line 1 "C:\\Users\\MLL\\Documents\\Arduino\\FORO\\FORO.ino"
// Line 1
// Line 10
// Line 20
// Line 30
// Line 40
// Line 41
// Line 42
// Line 43
// Line 44
// Line 45
// Line 46
// Line 47
// Line 48
// Line 49
#include <avr/wdt.h> // Line 50
#include <OneWire.h>
#include <DallasTemperature.h>
#include <MFRC522.h>
#include <SPI.h>
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoMatrix.h>
#include <string.h> //Line 58
void setup()
{
}
void loop()
{ }
Maybe i should open with notepad++ or hexeditor in order to see if a special character is added.
I wonder which is the libraries folder for IDE 2.1?
Because in 1.8 the IDE creates the path automatically
"C:\Users\MLL\Documents\Arduino\Libraries"
But IDE 2.1didn´t create it and I created by myself´´
Unfortunately I don't see any problem in that code and it compiles just fine. I expected to find some strange mistake that was introduced by the sketch pre-processor.
I think you have a good idea. I looked at the code you posted here without seeing anything, but the forum software might replace or remove such characters when the post is published.
Select File > Preferences from the Arduino IDE menus. In the "Preferences" dialog that opens, you will see a path in the "Sketchbook location" field. The libraries you install via the IDE's "Library Manager" and "Add ZIP Library..." features are stored in the libraries subfolder of that "Sketchbook location" path.
I'm glad it is working now. Even though it is not as satisfying as finding an explanation for the problem, I guess we can be happy enough that the problem is no longer occurring.
If it comes back later, let us know and we'll see if we are able to investigate further.
@sonofcymade the important discovery that the bug only occurs when the sketch is in an unsaved state (AKA "dirty"), where the code staged in the Arduino editor does not match the code in the file stored on your hard drive.
This was the essential condition that caused me to not be able to reproduce the fault. I had the "Auto save" feature enabled in my Arduino IDE preferences (it is enabled by default), which caused Arduino IDE to automatically save the sketch after I added the blank lines, thus causing the fault to not occur.
This means that the workaround for the bug is to select File > Save from the Arduino IDE menus before compiling or uploading the sketch.
The Arduino IDE developers are now tracking the bug here:
If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:
Please only comment on the GitHub issue thread if you have new technical information that will assist with the resolution. General discussion and support requests are always welcome here on the Arduino Forum.