Problem with a custom library

Hi,
First off let me say that I'm completely new to the Arduino family and am loving it so far :slight_smile: I'm having a problem with a custom library not compiling on a Arduino Sketch. I have a bunch of #defines and enums in a header file and have a few includes at the end of the header file. these definitions and enums are not being recognized by the compiler and am getting a bunch of undefined errors on the includes. I though about just including the definitions on the .c files but a few of them use the same definition and that will cause some more errors. what am I doing wrong?

Some of the code:

#ifndef __lib_gravity__
#define GRAVITY (-9.8)
#include <math.h>
#include <stdlib.h>

enum __Functions {D1=1,D2,D3,D4,D5,D6,D7,D8};


//Bunch of functions


#include "_zero.c" // uses Gravity
#include "_solve.c" // uses Gravity
#include "_recover.c" // uses the enum above
#endif

Thanks in advance for any help,
Jason

Read this before posting a programming question

Code tags. What errors?

Hi Nick,
Thanks for the reply, I will go through link and see if I can fix the problem I'm having. but I'm sorry I'm not sure what you mean by code Tags. but this is one of the errors I'm receiving:

C:\arduino-1.0.1\libraries\ballistics_solve.c: In function 'SolveAll':
C:\arduino-1.0.1\libraries\ballistics_solve.c:5: error: 'GRAVITY' undeclared (first use in this function)
C:\arduino-1.0.1\libraries\ballistics_solve.c:5: error: (Each undeclared identifier is reported only once
C:\arduino-1.0.1\libraries\ballistics_solve.c:5: error: for each function it appears in.)

I hope that helps. Please let me know if there was anything else that I forgot to include.

Thanks,
Jason

Why are you naming files with a leading underscore? That's rather unusual.

It's hard to give more details about a solution with only seeing a few snippets.

Perhaps attach a .zip file with all the relevant files.

I'm having a problem with a custom library not compiling on a Arduino

Let's put it another way: what custom library? Link to it?

Hi hjavaher,
the code you posted is unusual also for the following reasons:

  1. usually an header file content is inserted in a define block to avoid multiple inclusions, in this way:
#ifndef __lib_gravity__
#define __lib_gravity__
.....
#endif

but the define directive is missing.
2) why are you including .c files in a header?

I'm sorry I'm not sure what you mean by code Tags

Please do read the page linked by Nick. You question is answered in section 6 "Getting help on the forum".

Before you go too far down the path of creating a library using c files, keep in mind that the Arduino is programmed in C++. Using cpp files, even if they contain only C code makes using that code much easier.

c files can be used, but the calling convention for c functions is different than for c++ functions, so you'll have a lot of work to do to make your c functions usable to the Arduino sketch, which uses cpp calling conventions.