C语言 ... 对 ... collect2 的未定义引用:ld 返回 1 个退出状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23372897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
… undefined reference to … collect2: ld returned 1 exit status
提问by user38669
I'm having some errors when compiling and I can't figure out why...is my heapsort.h supposed to have an exported type?
我在编译时遇到了一些错误,我不知道为什么……我的 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:
堆排序.h:
#ifndef _HEAPSORT_H_INCLUDE_
#define _HEAPSORT_H_INCLUDE_
#include <stdio.h>
#include <stdlib.h>
void heapSort(int* keys, int numKeys);
#endif
when I go to compile with my client program I get this error upon compilation:
当我使用客户端程序进行编译时,编译时出现此错误:
HeapClient.o: In function `main':
HeapClient.c:(.text.startup+0x1a3): undefined reference to `heapsort'"
回答by T.C.
C (and C++) is case sensitive. Your function is called heapSort. Your HeapClient.c is apparently calling heapsort, so the linker complains that it can't find a heapsortfunction anywhere. Fix that typo and it should link.
C(和 C++)区分大小写。你的函数被称为heapSort。您的 HeapClient.c 显然正在调用heapsort,因此链接器抱怨它heapsort在任何地方都找不到函数。修复那个错字,它应该链接。

