...未定义的参考... collect2:LD返回1退出状态 [英] … undefined reference to … collect2: ld returned 1 exit status

查看:607
本文介绍了...未定义的参考... collect2:LD返回1退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译和我想不通为什么...是我heapsort.h应该有一个出口型?当有一些错误

heapsort.c

 的#include<&stdio.h中GT; //标准库已经包含在list.h
#包括LT&;&stdlib.h中GT;#包括heap.h
#包括heapsort.h无效堆排序为(int *键,诠释numKeys){
   heapHndl H = NULL;
   H = buildHeap(numKeys,钥匙,numKeys);
   的for(int i = 1; I< numKeys;我++){
      键[I] =包括maxValue(H);
      deleteMax(H);
   }
   freeHeap(安培; H);
}


heapsort.h:

 的#ifndef _HEAPSORT_H_INCLUDE_
#定义_HEAPSORT_H_INCLUDE_#包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;无效堆排序为(int *键,诠释numKeys);#万一


当我去和我的客户端程序编译,我得到在编译时这个错误:

  HeapClient.o:在函数'主':
HeapClient.c :( text.startup + 0x1a3):未定义的参考`堆排序'


解决方案

C(和C ++)区分大小写。你的函数被调用堆排序。您HeapClient.c显然是呼吁堆排序,因此链接器抱怨说,它不能在任何地方找到堆排序功能。修正了错字,它应该链接。

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

解决方案

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.

这篇关于...未定义的参考... collect2:LD返回1退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆