왜이 오류가 발생하는지 파악하려고합니까?C에서 다중 정의
/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'
이 함수의 이름을 디자인하는 데 사용 된 유일한 파일은 헤더 파일과 후속 구현 파일입니다. 구현이있다 동안
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을 추가했는데 문제가 발생 했습니까? 나는 또한 모든 헤더 파일에 대해 경비원을 확보하고 있으므로 여전히 혼란 스럽다. 선언과 정의에 문제가있는 것이 아닌가? zip 파일을보고
세이프 가드를 사용 했습니까? – gsamaras
둘 다 함수를 정의하는 두 개의 오브젝트 파일 ('ImageList.o'와'img.o')이있는 것처럼 보입니까? –
헤더 파일 정의를 변경하여 정의에 "extern"을 지정하십시오. – DrC