I'm trying to learn about library creation and have gotten stuck on what I suspect is a really simple error. My sketch includes a pair of simple files in their own subdirectory: led/blinkfile.h and led/blinkfile.cpp, but the compiler is complaining about the lone function inside them.
If I move the contents of "led/blinkfile.cpp" to the end of "led/blinkfile.h", the sketch compiles and functions as intended, but my goal is to learn how to create separate header and source files properly. Any help would be greatly appreciated!
Show the verbose error log in code tags.
Without seeing that, where is the blinkfile.cpp? What I mean is, is it in the source folder, or one of the library folders?
And therein lies the problem. The Adrduino IDE knows nothing of .cpp files in subdirectories.
Move the .h and .cpp files to the sketch directory. Change the include to remove the subdirectory reference. Add #include <Arduino.h> to your .cpp file (otherwise it knows nothing of the Arduino functions, like digitalWrite). Compiles like a charm.
The contents of the src subfolder are compiled recursively. Unlike the code files in the sketch root folder, these files are not shown as tabs in the IDEs.
The problem is that your blinkfile.cpp does not get compiled. The Arduino IDE does not compile files in arbitrary subdirectories of the sketch directory. All files you want to be compiled must be located in a subdirectory (tree) namend 'src' within your sktech directory.
This is what I was trying to achieve, a modular library that it self-contained within the sketch. Thanks to your reply, I just discovered my error: I had the "led" directory right there in the sketch's root directory. I just now added a "src" directory, moved the "led" directory into it, and changed the path in my sketch to "src/led/blinkfile.h" and it works!
Everyone's reply provided good information, but the reply from MicroBahner concisely describes exactly what I had to do and why, so I would like to mark that one as the solution.