0

I have an application where I would like to include an external multiline script as a const in my sketch. As far as I understand from C++11, this should work:

raw_string_literal_test.ino

const char *script = 
#include "script.txt"
;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

script.txt

R"(Line 1
Line 2
Line 3
Line 4
Line 5
Line 6)"

script.txt is placed in the same folder as raw_string_literal_test.ino

However, upon clicking Verify (selected board is Arduino/Genuino Uno, Arduino version is 1.6.12 on Mac OS 10.11.6) I get the following error:

/Users/owner/Desktop/raw_string/raw_string.ino:2:22: fatal error: script.txt: No such file or directory
 #include "script.txt"
                      ^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.

What am I doing incorrectly?

4
  • 2
    Try renaming the script to "script.h". Nov 14, 2016 at 12:24
  • Perfect - thanks Mikael - I am guessing the build recipe doesn't like the .txt extension!
    – stefandz
    Nov 14, 2016 at 12:36
  • I guess that you could have a "script.h" that includes a "script.txt" once the Arduino preprocessor is convinced that the sketch is using the local directory the path is included in the build/compile. Nov 14, 2016 at 13:15
  • That's a good point - but practically I can deal with a little renaming. The main aim is to avoid escape hell (and the readability issues that it brings) in putting a small test script into flash (on an ARM device).
    – stefandz
    Nov 14, 2016 at 13:18

1 Answer 1

2

Unlike other more "normal" build systems, the Arduino IDE doesn't compile the files in the project directory.

Instead it loads all the files with certain extensions into the IDE, each in its own tab. When you press the compile button it then writes the contents of each of those tabs to files in a temporary build folder and then compiles there.

Because of that only files with certain extensions ever get placed in the build folder. Those include:

  • .pde and .ino for sketch files
  • .c and .cpp for C and C++ source
  • .h for headers
  • .S for assembly source.

There may be a few others as well but those are the main ones. Things like text files aren't considered source files and thus aren't ever seen by the IDE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.