Mail Archives: djgpp/1998/05/09/08:45:30
From: | "John M. Aldrich" <fighteer AT cs DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Help with libraries?
|
Date: | Sat, 09 May 1998 08:37:52 -0400
|
Organization: | Two pounds of chaos and a pinch of salt.
|
Lines: | 80
|
Message-ID: | <35544E20.79CF@cs.com>
|
References: | <6j1eoj$8ml$1 AT news DOT metronet DOT de>
|
NNTP-Posting-Host: | ppp104.cs.net
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Lennart Marien wrote:
>
> So, what I want to do is to write several include files(BTW what are they
> called, couldn´t figure this out, yet!?!) and then write one which links
> them all to itself through
> #include<allmyfiles.h>...
> So that my main file only inludes this one and has access to all those
> functions in the
> other files.If I try to compile something like the above code I only get
> undefined reference for
> blah(1,2);.What can I do?
This is not a DJGPP problem, it's a basic C question. However, I'll
answer anyway because it's fun. :-) What you are talking about are
called "header" files, or "headers." They are supposed to contain
_declarations_ for code defined in other source modules or libraries.
You should never put actual code into a header, unless it's inlined.
Try this instead (and get a good C textbook to help you understand what
a header file is):
------- file1.h:
void blah(int x,int y);
------- file2.h:
void rababer(int z,short f,char r);
------- file1.c:
#include "file1.h"
void blah(int x,int y)
{
[...]
};
------- file2.c:
#include <file2.h>
void rababer(int z,short f,char r)
{
[...]
};
------- Main File:
#include <file1.h>
#include <file2.h>
int main(void)
{
rababer(1,2,3);
blah(1,2);
return 0;
};
----------
You would compile this as:
gcc -Wall -O -g -c file1.c
gcc -Wall -O -g -c file2.c
gcc -Wall -O -g -c main.c (whatever you call your main file)
gcc -o prog.exe main.o file1.o file2.o
hth!
--
John M. Aldrich <fighteer AT cs DOT com> - ICQ UIN# 7406319
* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
again.
* It doesn't necessarily do it in chronological order, though.
--- Douglas Adams
- Raw text -