Skip to content

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

Open
@notisrac

Description

@notisrac

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:

// test
#include "a.h"	

void setup() {
  uint8_t x = imaNumber;
}

void loop() {
}

a.h:

#ifndef TEST_H
#define TEST_H

uint8_t imaNumber = 5;

#endif // TEST_H

image

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?
  2. Why does the IDE use the first file in the tab list as the main code file?

Again, sorry if this is a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions