Just trying to figure out why I'm getting this error?
/import/ravel/1/cjmu065/cs1921/ass2/src/ImageList.c:21: multiple definition of `insert_at_tail'
img.o:/import/ravel/1/cjmu065/cs1921/ass2/src/ImageList.c:21: first defined here
ImageList.o: In function `printList':
/import/ravel/1/cjmu065/cs1921/ass2/src/ImageList.c:43: multiple definition of `printList'
img.o:/import/ravel/1/cjmu065/cs1921/ass2/src/ImageList.c:43: first defined here
ImageList.o: In function `make_empty_list':
/import/ravel/1/cjmu065/cs1921/ass2/src/ImageList.c:57: multiple definition of `make_empty_list'
The only files I have used to design these function names a header file and a subsequent implementation c file.
The header file includes these declarations:
void printList(ImageList *list);
ImageList *insert_at_tail(ImageList *list, char *name, QuadTree qtree, int dimen, int element);
ImageList *make_empty_list(void);
Whilst the implementation has this:
ImageList *insert_at_tail(ImageList *list, char *name, QuadTree qtree, int dimen, int element){
node_t *new;
new = malloc(sizeof(*new));
assert(list!=NULL && new!=NULL);
new->data.dim = dimen;
new->data.num = element;
new->data.filename = malloc(strlen(name)*sizeof(char));
strcpy(new->data.filename, name);
new->data.QuadTree = qtree;
new->next = NULL;
if(list->tail==NULL){
list->head = list->tail = new;
} else {
list->tail->next = new;
list->tail = new;
}
return list;
}
// print a list (space-separated, on one line)
void printList(ImageList *list)
{
node_t *cur;
for (cur = list->head; cur != NULL; cur = cur->next) {
printf("%d",cur->data.num);
printf(" [%2d]",cur->data.dim);
printf(" %s",cur->data.filename);
}
putchar('\n');
}
// Make an empty list of images
ImageList *make_empty_list(void)
{
ImageList *list;
list = malloc(sizeof(*list));
assert(list!=NULL);
list->head = list->tail = NULL;
return list;
}
I'm aware that the cause of this is usually from defining the function in the header file as well but it seems I haven't. I've looked through the files that I actually use these functions in but there are no extra definitions of the functions. The arguments and return values are also the same for both files so I'm kind of lost. Any help is appreciated.
CFLAGS=-Wall -g
img : img.o QuadTree.o ImageList.o
gcc -o img img.o QuadTree.o ImageList.o
img.o : img.c QuadTree.h ImageList.h
gcc $(CFLAGS) -c img.c
QuadTree.o : QuadTree.c QuadTree.h
gcc $(CFLAGS) -c QuadTree.c
ImageList.o : ImageList.c ImageList.h
gcc $(CFLAGS) -c ImageList.c
clean :
rm -f img img.o QuadTree.o ImageList.o core
I added my Makefile, is the problem arising this? I also have guards on all the header files, so I'm still extremely confused, is there anything wrong with the declarations and definitions?