Mail Archives: djgpp/1999/09/28/22:40:25
Okay, so now I have a header file with my routines declared and globals
and stuff called "subs.h" and I have a c program containing all these
subs called "subs.c" and I have a program called "prog.c" which contains
the line '#include "subs.h"'. I try to compile this using GCC (ie gcc
prog.c -o prog.exe) and I get error messages for all my subs which say:
c:/djgpp/tmp\cccqmssf(.text+0x123):prog.c:undefined referance to 'mysub'
or something similar.
I know I'm probably doing something really dumb but I can't figure it
out!
Thanks,
Alex
Ishpeck wrote:
>
> It's very simple. A header file is just a source file with the .h
> extension. When you import header, you'll usually go like so:
>
> #include "header.h"//Notice, it's in quotes, not <> thingies
>
> If your header is in a different directory as your source file, go like
> this.
>
> #include "other/dir/header.h"
>
> Voila! It's done!
>
> Inside your header, you might want it all within a special if statement,
> just so you don't over-declare anything. Like so
>
> #ifndef __MY_HEADER_NAME__ //The underscores are an arbitrary detail
> #define __MY_HEADER_NAME__
>
> //Header goes in here:
> //Function prototypes
> //Global variables
> //Constants, etc.
>
> #endif
>
> After that, you just treat it like a normal source file.
>
> Alex Mendes da Costa wrote:
> >
> > Hi All.
> > I know a bit about C programming (i.e. the basics) and wrote a list of C
> > routines that I want to be able to save seperately and then use them in
> > other programs I write. I don't know how to write a header file or
> > invoke the routines with it. Please Help!!
> >
> > Thanks,
> > Alex
>
> --
> Those who seek enlightenment
> may turn to Ishpeck the wise.
> http://come.to/ishpeck/
- Raw text -