Stuck on trying to compile 3 .c files with 2 includes .h files using my makefile
ID: 3594756 • Letter: S
Question
Stuck on trying to compile 3 .c files with 2 includes .h files using my makefile provided by my teacher. I'm compiling this using Oracle VM VirtualBox Ubuntu terminal window. My folder with everything in it is on my Home directory under "Project3" so "cd Project3" and I'm using the command "make p3". The files names are:
mex932p3.c BrowserList.c DoublyLinkedList.c
BrowserList.h DoublyLinkedList.h
Provided below is my makefile provided by my professor:
# Define the machine object files for your program
OBJECTS = mex932p3.o BrowserList.o DoublyLinkedList.o
# Define your include file
INCLUDES = BrowserList.h DoublyLinkedList.h
# make for the executable
p3: ${OBJECTS}
gcc -g -o p3 ${OBJECTS}
# Simple suffix rules for the .o
%.o: %.c ${INCLUDES}
gcc -g -c $<
# Clean the .o files
clean:
rm -f ${OBJECTS}
****Note I do have a #include "BrowserList.h" inside of my mxf942p3.c above main
**** error message below
~/Project3$ make p3
gcc -g -c BrowserList.c
BrowserList.c:10:1: error: unknown type name ‘BrowserList’
BrowserList newBrowserList()
^
BrowserList.c: In function ‘newBrowserList’:
BrowserList.c:13:1: error: unknown type name ‘BrowserList’
BrowserList temp = (BrowserList)malloc(sizeof(BrowserListImp));
^
BrowserList.c:13:21: error: ‘BrowserList’ undeclared (first use in this function)
BrowserList temp = (BrowserList)malloc(sizeof(BrowserListImp));
^
BrowserList.c:13:21: note: each undeclared identifier is reported only once for each function it appears in
BrowserList.c:13:33: error: expected ‘,’ or ‘;’ before ‘malloc’
BrowserList temp = (BrowserList)malloc(sizeof(BrowserListImp));
^
BrowserList.c:15:5: error: invalid type argument of ‘->’ (have ‘int’)
temp->pHead = NULL;
^
BrowserList.c:15:15: error: ‘NULL’ undeclared (first use in this function)
temp->pHead = NULL;
^
BrowserList.c:16:5: error: invalid type argument of ‘->’ (have ‘int’)
temp->pFoot = NULL;
^
BrowserList.c: At top level:
BrowserList.c:33:22: error: unknown type name ‘BrowserList’
void freeBrowserList(BrowserList browserList)
^
BrowserList.c:52:14: error: unknown type name ‘BrowserList’
void goToURL(BrowserList browserList, Element element)
^
BrowserList.c:52:39: error: unknown type name ‘Element’
void goToURL(BrowserList browserList, Element element)
^
BrowserList.c:100:10: error: unknown type name ‘BrowserList’
int back(BrowserList browserList)
^
BrowserList.c:122:13: error: unknown type name ‘BrowserList’
int forward(BrowserList browserList)
^
BrowserList.c:144:23: error: unknown type name ‘BrowserList’
void printBrowserList(BrowserList browserList)
^
Makefile:12: recipe for target 'BrowserList.o' failed
make: *** [BrowserList.o] Error 1
Explanation / Answer
Include not adding your DoublyLinkedList.h file. better to give header file directly instad of
%.o: %.c ${INCLUDES} try
%.o: %.c BrowserList.h DoublyLinkedList.h
may be it will work properly.