libraries file depends on project file

PLEASE SKIP DOWN TO POST #5 FOR A CLEAR DESCRIPTION OF THE ISSUE.

Usually project files depend on library files.
In this sketch it's the other way around, some library files depend on a project file.

Here is the directory structure:

Documents\Arduino\libraries\polymorph_lib\
	Der1.h
	Der1.cpp
projects\polymorph\
	polymorph.ino
	userClass.h
	userClass.cpp

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?

I can attach the files if that would help.

Thank you.

Is there a way for Arduino IDE to find the userClass file?

I can attach the files if that would help.

Yes, it can, and yes, it would.

Thanks for taking a look PaulS. The files are attached.

polymorph.zip (38 KB)

polymorph_lib.zip (5.23 KB)

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?)

There is probably a way to bash past this with

#include "../../../../projects/polymorph/userClass.h"

or similar, but I wouldn't recommend it.

Hi MarkT,

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:

sketch1\
	sketch1.ino
	CustomClass.h

sketch2\
	sketch2.ino
	CustomClass.h
	
Arduino\libraries\lib_folder\
	LibClass.h                        << LibClass.h depends on CustomClass.h

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 ?

Thank you.

libClass_depend_on_sketchClass.zip (3.8 KB)