Go Down

Topic: Can't include library from header file (Read 4473 times) previous topic - next topic

progman32

May 20, 2009, 10:12 pm Last Edit: May 20, 2009, 10:14 pm by progman32 Reason: 1
Hey all, I'm new here. Have been having a lot of fun with my trusty arduino 328, but i've run into a problem. I can import libraries as expected from regular source files, but not from .h's. If i try to import any library from a .h, it fails to find the relevant header. Smallest example that breaks:

Main sketch:
Code: [Select]

#include "Cls1.h"
void setup(){
 Cls1 bill();
}
void loop(){}


Cls1.h:
Code: [Select]

//FAILS HERE with error: EEPROM.h: No such file or directory
#include <EEPROM.h> //can be any library, just an example.
class Cls1
{
private:
public:
 Cls1();
};


Cls1.pde:
Code: [Select]

#include "Cls1.h"
Cls1::Cls1() {
}


Any ideas? I admit I'm not very good at C++, I may be overlooking something stupid.

EDIT: Arduino 0015 on WinXP.

AlphaBeta

#1
May 20, 2009, 10:39 pm Last Edit: May 20, 2009, 10:40 pm by AlphaBeta Reason: 1
Try:
Cls1.h
Code: [Select]

#ifndef CLS1_H
#define CLS1_H
#include <EEPROM.h> //can be any library, just an example.
class Cls1
{
private:
public:
 Cls1();
};
#endif

progman32

Thanks for your help. Unfortunately, the behavior is the same...

AlphaBeta

Main sketch:
Code: [Select]

#include <EEPROM.h> //include the library Cls1 uses here.
#include "Cls1.h"
void setup(){
 Cls1 bill();
}
void loop(){}

progman32

Yeah, that's what I'm doing at the moment, it's a workaround. I just don't like the order of my #includes to matter.
That said, I'll just go with this way for now. I'll update if I find out something. Thanks!

AlphaBeta

Maybe this would work in the header:

Code: [Select]
#include "../EEPROM/EEPROM.h"

wayoda

Hi,
as you might know an arduino-sketch (pde-file) has to be preprocessed by the IDE to turn it into plain C-code that is handed over to the compiler.
This involves  searching for all library-include statements in the main pde-file, and adding a compiler-directive to have them included in the resulting upload-code.

But the arduino-preprocessor does not do this for your extra *.h or .*cpp in your sketch. So what you are trying is not possible (with the current arduino-IDE version).

Eberhard



D???L?

I've walked into this problem too when I needed to use the SPI library from an header file, but I made a workaround.
This should work:
Code: [Select]
#include <../../../../libraries/EEPROM/EEPROM.h>

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy