arduino / arduino/Arduino

Case difference in the sketch folder and file name causes the IDE to try to compile the wrong file

Open
#8,030 1 comment 1 reaction 0 assignees View on GitHub
Component: IDE OS: Windows Type: Bug
Dominant language
Java
Stars
14.6k
Forks
7k
PR merge metrics
No merged PRs in 30d

Description

Bear with me on this one, as it is a bit complicated to explain :) Also, sorry if this is a dupe - I tried searching, but found nothing.

**The scenario**:
- OS is Windows
- You have a sketch folder named "Test"
- You have an .ino file and at least one .h file in that folder (Named test.ino and a.h)
- (The sketch file includes the .h file)
- In an alphabetical order, the .h file's name is ahead the .ino file's name
- The case of the first letter of the .ino file's name does not match the case of the sketch folder's name's first letter (The other letters don't matter)

**The bug**:
When you load this sketch into the IDE, the .h file will come **before** the .ino file in the tab list! This will result in the IDE treating the .h file as the main program code, and will pass that to the compiler.

**Example**:
Sketch folder structure:
C:\Test\test.ino
C:\Test\a.h

_Note the following_:
- The name of the sketch folder and the .ino file differs in the case of the letter 'T' only!
- The name of the header file 'a' is before the letter 't' in the alphabetical order
- It will also work with the following: C:\tEST\Test.ino

test.ino:
```cpp
// test
#include "a.h"

void setup() {
uint8_t x = imaNumber;
}

void loop() {
}
```

a.h:
```cpp
#ifndef TEST_H
#define TEST_H

uint8_t imaNumber = 5;

#endif // TEST_H
```

![image](https://user-images.githubusercontent.com/13077218/46039085-1bcdae00-c10d-11e8-89a5-36302f1fc116.png)

When trying to build this, the IDE will present you with an error message: `test:2:16: error: a.h: No such file or directory`

Further analysis of the output panel reveals the cause of the error message:
```
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs ... (snip) ... -verbose C:\Test\a.h
C:\Program Files (x86)\Arduino\arduino-builder -compile ... (snip) ... -verbose C:\Test\a.h
...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c ... (snip) ... "C:\\Users\\me\\AppData\\Local\\Temp\\arduino_build_814342\\sketch\\a.h.cpp" -o nul
```
Note, that both of the `arduino-builder` executions get the `a.h` as the file to be built, just like `avr-g++` gets `a.h.cpp`.

This does not happen in any other case, than this! (Try renaming `a.h` to `z.h`)

Tested with v1.8.6, v1.8.7, v1.8.7 Hourly Build 2018/09/20 02:27, 1.8.14 Hourly Build 2021/03/09 09:33

So there are two questions I have regarding this issue:
1. Why is there a difference between the upper and lower case names - and why only the first character?
1. Why does the IDE use the first file in the tab list as the main code file?

Again, sorry if this is a duplicate.

Contributor guide

Open the contributing guide

Research direction

Reproduce the case-sensitive Windows scenario with C:\Test\test.ino and C:\Test\a.h, then inspect how the IDE orders tabs and invokes arduino-builder. Compare the -dump-prefs and -compile paths shown in the issue, and confirm done when the .ino file is selected as the main code and the sketch builds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, java
Domain
desktop-dev, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.