Wiring Forum
Programming Questions & Help >> Syntax >> How to include header file to sketch?

Message started by redman on 02/04/09 at 20:27:52

Title: How to include header file to sketch?
Post by redman on 02/04/09 at 20:27:52
Hi all,

I have this situation:

1 project file.
1 .h file with globally defined structs/types.
1 .cpp file with global functions.

If i try to declare a variable of my type within setup() the compiler doesnt know the type (or type is out of scope).

But if i try to include the header file in the project then i get double declaration errors. So it is already known.

Also, if i declare this struct globally in the project file then it works (but i want to keep the project file tidy and clean)

So my question is how can i add a header file to the project .
Or, how do i split the project file to make it more manageble.

Title: Re: How to include header file to sketch?
Post by barragan on 02/10/09 at 03:17:12
Go to your Wiring isntallation folder inside libraries and create a floder for your library, you can look inside and see the libraries included in the distribution, put your files in there, and your library will be compiled when you press the play button the next time in the editor. From now on you can use the #include <yourinclude.h> directive in your sketch to include your library, or go to the Sketch -> Import library menu and select your library. Let me know.

Title: Re: How to include header file to sketch?
Post by redman on 02/11/09 at 12:01:43
Aah, thank you.

It seems to be working now.
But now the library is outside the IDE.
I need to manualy delete the .o file before i can compile it.
Usualy this is not a big problem, but i'm not a very good programmer, so i need to test a lot, so i compile a lot. :)

So maybe this is something for the next release? :
Option to force re-compile of libraries when you do a normal compile.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.