so I have 3 files which I intend to link with a make file.
do I need to include #include for the libraries for the c files that don't contain main?
I also have header files for the two .c files which don't contain main. Do I need to #include the "nameoffile.h" on the top of the .c files?
I.E. I have 3 .c files A B and C. B and C contain header files. A contains main. B calls a function from C. I'm getting an error "undefined reference to function" how do I define it?
I've been debugging for a while and trying to understand but can't seem to figure it out.
You need a header file to forward-declare any function you intend to call within that specific file (or, to be more correct, within that "Compilation Unit").
So if I'm calling a function in C while I'm in a function in B, I need to #include the C header file in A,B and C?
you need to include it in B and C
pastebin'ing some source code might make it easier to help you out
thanks! I found the problem, I didn't include the header files in the make file.
But for some reason it has been working before? Do you know why?
wonderful, it no longer works.
Ok here's what I got.
I have 5 files. rsvp.c, courses.c, courses.h, vector.c, vector.h
rsvp.c calls a function from courses.c and then courses.c calls a function in vector.c
in terms of #include
rsvp.c: #includes "courses.h"
courses.c: #includes "vector.h"
and my makefile goes as follows
rsvp.out: rsvp.o course.o vector.o
gcc -Wall 0g rsvp.o -o rsvp.out
rsvp.o: rsvp.c courses.h
gcc -Wall -g -c rsvp.c
course.o: courses.c courses.h vector.h
gcc -Wall -g -c courses.c
vector.o: vector.c vector.h
gcc -Wall -c vector.c
I've asked every programming literate person in my dorm and everyone is stumped. Please help!
wonderful, it no longer works.
Ok here's what I got.
I have 5 files. rsvp.c, courses.c, courses.h, vector.c, vector.h
rsvp.c calls a function from courses.c and then courses.c calls a function in vector.c
in terms of #include
rsvp.c: #includes "courses.h"
courses.c: #includes "vector.h"
and my makefile goes as follows
rsvp.out: rsvp.o course.o vector.o
gcc -Wall 0g rsvp.o -o rsvp.out
rsvp.o: rsvp.c courses.h
gcc -Wall -g -c rsvp.c
course.o: courses.c courses.h vector.h
gcc -Wall -g -c courses.c
vector.o: vector.c vector.h
gcc -Wall -c vector.c
I've asked every programming literate person in my dorm and everyone is stumped. Please help!
Daz
March 9 2009 4:26 AM EDT
"gcc -Wall 0g rsvp.o -o rsvp.out"
-g?
gcc -Wall 0g rsvp.o -o rsvp.out
should be
gcc -Wall -g courses.o vector.o rsvp.o -o rsvp.out
"rsvp.c calls a function from courses.c and then courses.c calls a function in vector.c"
Are the functions declared in the header and implemented in the source file?
you got it Nightstrike :D. Thanks! I knew the CB community could help.
A little token of gratitude
three4thsforsaken (Single Minion) 128.120.173.122 AdminNightStrike (The Iconics 3e) $500000 12:34 PM EDT
This thread is closed to new posts.
However, you are welcome to reference it
from a new thread; link this with the html
<a href="/bboard/q-and-a-fetch-msg.tcl?msg_id=002gMl">desperate C programing question</a>