use*_*669 2 c undefined-reference
编译时我遇到了一些错误,我无法弄清楚为什么......我的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);
}
Run Code Online (Sandbox Code Playgroud)
heapsort.h:
#ifndef _HEAPSORT_H_INCLUDE_
#define _HEAPSORT_H_INCLUDE_
#include <stdio.h>
#include <stdlib.h>
void heapSort(int* keys, int numKeys);
#endif
Run Code Online (Sandbox Code Playgroud)
当我使用我的客户端程序编译时,我在编译时遇到此错误:
HeapClient.o: In function `main':
HeapClient.c:(.text.startup+0x1a3): undefined reference to `heapsort'"
Run Code Online (Sandbox Code Playgroud)
C(和C++)区分大小写.你的函数被调用heapSort.您的HeapClient.c显然正在调用heapsort,因此链接器抱怨它无法在heapsort任何地方找到函数.修复拼写错误,它应该链接.