…未定义引用… collect2:ld返回1退出状态
编译时我遇到了一些错误,我无法弄清楚为什么……我的heapsort.h应该有导出类型吗?
heapsort.c
#include // standard libraries already included in "list.h" #include #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 #include void heapSort(int* keys, int numKeys); #endif
当我使用我的客户端程序编译时,我在编译时遇到此错误:
HeapClient.o: In function `main': HeapClient.c:(.text.startup+0x1a3): undefined reference to `heapsort'"
C(和C ++)区分大小写。 您的函数称为heapSort
。 你的HeapClient.c显然是在调用heapsort
,所以链接器抱怨它无法在任何地方找到一个heapsort
函数。 修复拼写错误,它应该链接。