Go Down

Topic: splitting project (Read 1 time) previous topic - next topic

_frank_

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

e.g.
main file (templogger.ino)
Code: [Select]

#include "temp.h"
void setup(void)
{
  Serial.begin(9600);
}

void loop(void)
{}

temp.h:
Code: [Select]
#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 :)

frank

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

_frank_

Hi,
thank you for the answer,i'll try that.
btw. temp does not stand for temporary but for temperature... ;)
Regards Frank

_frank_

hi,
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*
Code: [Select]

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

PaulS

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

// 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.
The art of getting good answers lies in asking good questions.

_frank_

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

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

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

_frank_

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

thx

Go Up