1

I have encountered a problem when calling my freeHeap function inside of sortComp.c

I am calling it as such

heapRef myHeap = buildHeap(numData, heapSort, numData);     

freeHeap(myHeap);

When compiling I recieve the error "Undefined reference to 'freeHeap'"

I am including heap.h and inside of heap.h i have declared freeHeap

void freeHeap(heapRef *);

I am compiling it as such

gcc -o sortComp sortComp.c insertionSort.c heap.c insertionSort.h heap.h

It is defined in heap.c as

void freeHeap(heapRef *pH){
   heapRef H = *pH;
   free(H->data);
   free(H);
}

FIXED:

I changed the calling of freeHeap(myHeap);

to

freeHeap(&myHeap);

and it stopped complaining

4

2 回答 2

0

在你的函数声明中使用freeHeap()heap.h

  extern void freeHeap(heapRef*);

编辑耶稣基督,你的论点freeHeap()与原型不匹配,就像你的声明与你的定义不匹配一样。所以你的论点需要是类型heapRef*而不是。heapRef在你的程序myHeap是类型heapRef,而你应该通过heapRef*。用这个:

freeHeap(&myHeap);
于 2013-05-03T00:21:29.983 回答
0

请从您的编译命令中取出 .h 文件。应该是:

gcc -o sortComp sortComp.c insertionSort.c heap.c
于 2013-05-03T00:24:02.373 回答