Pages: [1]   Go Down
Author Topic: Can't include library from header file  (Read 2876 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#include "Cls1.h"
void setup(){
  Cls1 bill();
}
void loop(){}

Cls1.h:
Code:
//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:
#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.
« Last Edit: May 20, 2009, 03:14:15 pm by progman32 » Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try:
Cls1.h
Code:
#ifndef CLS1_H
#define CLS1_H
#include <EEPROM.h> //can be any library, just an example.
class Cls1
{
private:
public:
  Cls1();
};
#endif
« Last Edit: May 20, 2009, 03:40:23 pm by AlphaBeta » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe this would work in the header:

Code:
#include "../EEPROM/EEPROM.h"
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Portugal
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#include <../../../../libraries/EEPROM/EEPROM.h>
Logged

Pages: [1]   Go Up
Jump to: