编译时我遇到了一些错误,我无法弄清楚为什么...我的heapsort.h应该有导出类型吗?
heapsort.c
#include <stdio.h> // standard libraries already included in "list.h"
#include <stdlib.h>
#include "heap.h"
#include "heapsort.h"
void heapSort(int* keys, int numKeys){
heapHndl H = NULL;
H = buildHeap(numKeys, keys, numKeys);
for (int i = 1; i < numKeys; i++){
keys[i] = maxValue(H);
deleteMax(H);
}
freeHeap(&H);
}
heapsort.h:
#ifndef _HEAPSORT_H_INCLUDE_
#define _HEAPSORT_H_INCLUDE_
#include <stdio.h>
#include <stdlib.h>
void heapSort(int* keys, int numKeys);
#endif
当我使用我的客户端程序编译时,我在编译时遇到此错误:
HeapClient.o: In function `main':
HeapClient.c:(.text.startup+0x1a3): undefined reference to `heapsort'"
答案 0 :(得分:6)
C(和C ++)区分大小写。您的函数名为heapSort
。您的HeapClient.c显然正在调用heapsort
,因此链接器抱怨它无法在任何地方找到heapsort
函数。修复拼写错误,它应该链接。