The sketch does not find include files

Hello,
I'm programming with Arduino Uno in Mint 18. I want to reuse fragments of source code in various sketches, and for that I want to include in my sketch those fragments like this:

#include "source1.txt"
#include "source2.txt"

The files are in the same folder as the sketch, but my sketch does not detect them. However, if I use the full path it works fine:
#include "/home/user/arduino/programs/program1/source1.txt"
I do not like that, because it's less portable.

When I compile a program in C language with gcc, that does not happen.

Why does Arduino work like this?

From Arduino - BuildProcess

Multi-file sketches

A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the “main sketch file”. Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using “double quotes” not ).

So if you remove the .txt extensions those files will be merged automatically! (This is an arduino-specific function not a usual thing)

If you want to make you code into a proper library to use across projects then Arduino - LibraryTutorial might help

If all else fails then try “#include ./source1.txt” to see if that slightly improves portability.

The Arduino will not use the style “#include ./source1.txt” because when the compiler starts work on the .ino file it will have been copied to a different directory.

The 3 simple options are

#include
#include “file in the same folder as the .ino file”
#include “file with full absolute path name”

I have no trouble with #include “myFile.h”. It is possible it does not like the .txt extension

For my own use I have written a short Python program that converts relative paths to absolute paths before calling the Arduino IDE to compile and upload the program.

…R

It is possible it does not like the .txt extension

Exactly. Some of the newer versions of the IDE have restricted the kinds of extensions supported. No programming language uses txt as the extension, so there is no reason to support it.

Thank you very much to all.

Putting the myFile.h file in the .ino folder with #include "myFile.h" works perfectly, the problem was that the IDE does not seem to support the .txt extension

So if you remove the .txt extensions those files will be merged automatically! (This is an arduino-specific function not a usual thing)

It does not work for me (IDE 2:1.0.5+dfsg2-4), it just works for me if I add explicitly #include "myFile.h" in the .ino header.

P.S. A suggestion: In 'About Arduino' the string "2:1.0.5+dfsg2-4" can not be copied >:( , it would be nice to copy instead of having to transcribe ...