我经常看到错误collect2: error: ld returned 1 exit status.例如,我正在执行以下代码片段:

void main() {
  char i;

  printf("ENTER i");
  scanf("%c",&i);

  clrscr();

  switch(i) {
    default:
      printf("\nHi..\n");
      break;
    case 1:
      printf("\n\na");
      break;
    case 2:
      printf("\nb\n");
      break;
    case 3:
      printf("\nc");
      break;
  }
}

我得到了这个:

main.c:(.text+0x33): undefined reference to `clrscr'                       
collect2: error: ld returned 1 exit status 

这是什么意思?

推荐答案

The ld returned 1 exit status error is the consequence of previous errors. In your example there is an earlier error - undefined reference to 'clrscr' - and this is the real one. The exit status error just signals that the linking step in the build process encountered some errors. Normally exit status 0 means success, and exit status > 0 means errors.

When you build your program, multiple tools may be run as separate steps to create the final executable. In your case one of those tools is ld, which first reports the error it found (clrscr reference missing), and then it returns the exit status. Since the exit status is > 0, it means an error and is reported.

在许多情况下,工具返回它们遇到的错误数作为退出状态.因此,如果ld工具发现两个错误,其退出状态将为2.

C++相关问答推荐

uintPtr_t上的算术

新的memaligning函数有什么用?

CC crate 示例不会与C函数链接

Mbed TLS:OAEP的就地en—/decryption似乎不起作用'

丑陋的三重间接:可扩展的缓冲区管理 struct

为什么在函数内部分配内存空间时需要添加符号?

每个 struct 变量在C中都有自己的命名空间吗?

如何将字符**传递给需要常量字符指针的常量数组的函数

将uintptr_t添加到指针是否对称?

struct -未知大小

我怎么才能用GCC编译一个c库,让它包含另一个库呢?

==284==错误:AddressSaniizer:堆栈缓冲区下溢

如何在GDB中查看MUSL的源代码

关于scanf()和空格的问题

如何用C语言为CLI应用程序编写按键检测系统?

当用C打印过多的';\n';时输出不正确

共享目标代码似乎不能在Linux上的进程之间共享

从文件到链表读取日期

我可以使用Windows SDK';s IN6_IS_ADDR_LOOPBACK等,尽管没有文档?

为什么写入关闭管道会返回成功