splitting project

i want to split my current project into multiple files, but i have trouble with importing libs.

main file (templogger.ino)

#include "temp.h"
void setup(void) 

void loop(void) 


#include <OneWire.h>
//init the one wire interface on pin 10
OneWire ow(10);

byte sensors[4][8];
int sensor_count=0;

if i try to compile, the lib OneWire.h is not found, if i copy this in ino-file, it is found…

what’s wrong?
how can i use libs in header-files?
i also want to call functions in h from my ino, so i cannot use extension ino for the h-file.

i hope i described it clear enough :slight_smile:


how can i use libs in header-files?

Sketches, and any files referenced in a sketch, and any source files that go with them, are copied to a temp. directory for compiling. If you do not include OneWire.h in the sketch, it is not copied. Then, when the compiler tries to compile code that references temp.h (a really lousy name, by the way), it can’t find OneWire.h

So, any libraries that your library needs, must be included in the sketch, too.

thank you for the answer,i’ll try that.
btw. temp does not stand for temporary but for temperature… :wink:
Regards Frank

i’ve ried it and this seems to work…

now i got errormessage “templogger.cpp:15: Fehler: expected constructor, destructor, or type conversion before »;« token”

templogger.cpp from /tmp/build*

14 #include "sdcard.h"
15 setup_sd();

sdcard.h is a modified version of the example…i’ve attached that file
it was a working ino before where i renamed setup to setup_sd and removed loop.

regards Frank

sdcard.h (3.32 KB)

I opened your file in Notepad++, and collapsed the comments and setup_sd() functions. What is left is this:

 // include the SD library:

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

void setup_sd()

It appears that you ignored the first C++ style comment. Therefore, the compiler has no idea what a Sd2Card, SdVolume, and SdFile are. Hence the complaint.

i have included the sd-library in the ino-file before importing the sdcard.h

Sd2Card, SdVolume, and SdFile are classes inside this sd-library

12 #include <SD.h>
13 const int SlaveSelect_SDCard=53;
14 #include "sdcard.h"
15 setup_sd();

i have included the sd-library in the ino-file before importing the sdcard.h

You must include it in sdcard.h, too. Included files are file-specific. They are not shared.

import only in ino works too, but i have to move the function-call setup_sd() to the setup()-function.