undefined reference to错误!

leopardaa521 2011-07-13 01:54:45
下面的代码gcc的时候提示下面的错误,看半天没找出哪有毛病,请教高手指点!
/tmp/ccmKb9yz.o: In function `sort':
test.c:(.text+0x1f5): undefined reference to `merge'
collect2: ld 返回 1


#include <stdio.h>

#define MAXSIZE 8
int arr[MAXSIZE] = { 5, 7, 2, 1, 9, 4, 3, 8 };

void merger(int start, int mid, int end) {
int len1 = mid - start + 1;
int len2 = end - mid;
int left[len1];
int right[len2];
int i, j, k;
// 相邻子序列赋值
for (i = 0; i < len1; i++)
left[i] = arr[start + i];
for (j = 0; j < len2; j++)
right[j] = arr[mid + 1 + j];
// 合并相邻两个有序子序列
i = j = 0;
k = start;
while (i < len1 && j < len2)
if (left[i] < right[j])
arr[k++] = left[i++];
else
arr[k++] = right[j++];
// 检查是否合并完毕
while (i < len1)
arr[k++] = left[i++];
while (j < len2)
arr[k++] = right[j++];
}

void sort(int start, int end) {
int mid;
if (start < end) {
mid = (start + end) / 2;
sort(start, mid);
sort(mid + 1, end);
merge(start, mid, end);
}
}

int main(int argc, char**argv) {
sort(0, MAXSIZE - 1);
int index = 0;
for (index = 0; index < MAXSIZE; index++)
printf("%d ", arr[index]);
return 0;
}


...全文
322 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
TitanQuest 2011-07-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 abao623660072 的回复:]

引用 4 楼 titanquest 的回复:
/tmp/ccmKb9yz.o: In function `sort':
test.c:(.text+0x1f5): undefined reference to `merge'
collect2: ld 返回 1

意思就是说,在文件test.c中的函数sort中,存在一个叫做merge未定义的东西,


不是告诉你了吗? 写错了啊……
[/Quote]
呵呵,高手告诉我没有用,你要告诉楼主呀
金刚葫芦娃 2011-07-13
  • 打赏
  • 举报
回复
4楼,看错了,我以为是楼主,sorry.
TitanQuest 2011-07-13
  • 打赏
  • 举报
回复
错误信息提示,要学着看,多了就熟练了,
最后你可能看到提示就知道那个地方错了
金刚葫芦娃 2011-07-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 titanquest 的回复:]
/tmp/ccmKb9yz.o: In function `sort':
test.c:(.text+0x1f5): undefined reference to `merge'
collect2: ld 返回 1

意思就是说,在文件test.c中的函数sort中,存在一个叫做merge未定义的东西,
[/Quote]

不是告诉你了吗? 写错了啊 , 调用的时候函数少写了一个r
TitanQuest 2011-07-13
  • 打赏
  • 举报
回复
/tmp/ccmKb9yz.o: In function `sort':
test.c:(.text+0x1f5): undefined reference to `merge'
collect2: ld 返回 1

意思就是说,在文件test.c中的函数sort中,存在一个叫做merge未定义的东西,
ouyh12345 2011-07-13
  • 打赏
  • 举报
回复
全文查找先
bdmh 2011-07-13
  • 打赏
  • 举报
回复
merger
merge ??
金刚葫芦娃 2011-07-13
  • 打赏
  • 举报
回复
void merger(int start, int mid, int end) {
merge(start, mid, end);
调用的时候,函数少了一个r

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧