… undefined reference to … collect2: ld returned 1 exit status [duplicate]

风格不统一 提交于 2019-12-11 03:24:49

问题


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.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

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'"

回答1:


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 heapsort function anywhere. Fix that typo and it should link.



来源:https://stackoverflow.com/questions/23372897/undefined-reference-to-collect2-ld-returned-1-exit-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!