UserClass is a User defined class in a project directory.
Class Der1 is in Arduino libraries.
Class Der1 depends on UserClass.
The code is good, it has been compiled with a Makefile and tested.
But Arduino IDE is not finding the userClass file.
Arduino IDE gets this compile error:
In file included from polymorph.ino:1:
C:\Users\wolf\Documents\Arduino\libraries\polymorph_lib/Der1.h:8: error: expected class-name before '{' token
Arduino\libraries\polymorph_lib\Der1.h:
#ifndef DER1_H
#define DER1_H
#include <UserClass.h>
class Der1 : public UserClass
{
public:
void press();
};
#endif
Is there a way for Arduino IDE to find the userClass file?
You need to move the UserClass into a library, or bring the Der1 class into the sketch
folder - libraries shouldn't be depending on the sketch using them (what if two sketches
both have a UserClass?)
The UserClass is a user defined class, so the user would have to import it into the library.
I guess that's not so bad.
There are actually a bunch of Der files: Der1, Der2, Der3, ...
The user could copy and paste them from the library to the project file, but that defeat the purpose of a library.
Usually project files depend on library files.
But sometimes its useful to have dependences in the other direction.
In the attached example, a library file depends on a sketch file.
Here is the example's directory structure:
Each sketch has a CustomClass.h file.
The code within the customClass files is different for each sketch.
The LibClass.h includes CustomClass.h
To compile sketch1.ino on Arduino 1.0.6 IDE, the user needs to move the corresponding CustomClass.h into lib_folder.
To compile sketch2.ino, the user needs to move that CustomClass.h into lib_folder.
Moving files in and out of libraries is dangerous and requires deleting Arduino's AppData\Local\Temp\build folder.
All the CustomClass files are moved in and out of the library every time all the sketchX.ino programs are regression tested.
Regression testing each versions of sketchX.ino will become impractical as more versions of sketchX.ino are added.
And instructing library users to move CustomClasses into the library is not very user friendly.
If CustomClass.h is not moved into the lib_folder, Arduino 1.0.6 IDE does not find the CustomClass.h file.
Here is the verbose error message:
Arduino: 1.0.6 + Td: 1.20 (Windows 7), Board: "Teensy 2.0"
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega32u4 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -DTEENSYDUINO=120 -felide-constructors -std=c++0x -DUSB_HID -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\cores\teensy -IC:\Users\wolf\Documents\Arduino\libraries\lib_folder C:\Users\wolf\AppData\Local\Temp\build5396932314268139837.tmp\main.cpp -o C:\Users\wolf\AppData\Local\Temp\build5396932314268139837.tmp\main.cpp.o
In file included from main.cpp:1:
C:\Users\wolf\Documents\Arduino\libraries\lib_folder/LibClass.h:4:25: warning: CustomClass.h: No such file or directory
In file included from main.cpp:1:
C:\Users\wolf\Documents\Arduino\libraries\lib_folder/LibClass.h:9: error: 'CustomClass' does not name a type
C:\Users\wolf\Documents\Arduino\libraries\lib_folder/LibClass.h: In member function 'void LibClass::fn()':
C:\Users\wolf\Documents\Arduino\libraries\lib_folder/LibClass.h:11: error: 'customObj' was not declared in this scope
Is there a fundamental reason why Arduino IDE can not compile library files that depend on sketch files?
Is there a better way?
Is this issue something that should be posted to Issues · arduino/Arduino · GitHub ?