From: "John M. Aldrich" 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 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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... > 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 void rababer(int z,short f,char r) { [...] }; ------- Main File: #include #include 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 - 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