このエラーが発生する理由を理解しようとしているだけですか?
/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'
これらの関数名を設計するために使用した唯一のファイルは、ヘッダー ファイルと後続の実装 c ファイルです。
ヘッダー ファイルには、次の宣言が含まれます。
void printList(ImageList *list);
ImageList *insert_at_tail(ImageList *list, char *name, QuadTree qtree, int dimen, int element);
ImageList *make_empty_list(void);
実装にはこれがありますが:
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;
}
これの原因は通常、ヘッダー ファイルでも関数を定義していることにあることは承知していますが、そうではないようです。これらの関数を実際に使用するファイルを調べましたが、関数の追加定義はありません。引数と戻り値も両方のファイルで同じなので、ちょっと迷っています。どんな助けでも大歓迎です。
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
Makefile を追加しましたが、これによって問題が発生していますか? また、すべてのヘッダー ファイルにガードを付けているので、まだ非常に混乱しています。宣言と定義に何か問題がありますか?