C语言 “collect2:错误:ld 返回 1 个退出状态”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27272525/
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
What does "collect2: error: ld returned 1 exit status" mean?
提问by user3682120
I see the error collect2: error: ld returned 1 exit statusvery often. For example, I was executing the following snippet of code:
我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;
}
}
and I got this:
我得到了这个:
main.c:(.text+0x33): undefined reference to `clrscr'
collect2: error: ld returned 1 exit status
What does it mean?
这是什么意思?
回答by Wojtek Surowka
The ld returned 1 exit statuserror 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 0means success, and exit status> 0 means errors.
该ld returned 1 exit status错误是前面的错误的结果。在您的示例中,有一个较早的错误 - undefined reference to 'clrscr'- 这是真正的错误。退出状态错误只是表明构建过程中的链接步骤遇到了一些错误。通常exit status 0表示成功,exit status> 0 表示错误。
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 (clrscrreference missing), and then it returns the exit status. Since the exit status is > 0, it means an error and is reported.
构建程序时,多个工具可能会作为单独的步骤运行以创建最终的可执行文件。在您的情况下,这些工具之一是ld,它首先报告它发现的错误(clrscr缺少引用),然后返回退出状态。由于退出状态> 0,表示有错误,会报错。
In many cases tools return as the exit status the number of errors they encountered. So if ldtool finds two errors, its exit status would be 2.
在许多情况下,工具将它们遇到的错误数量作为退出状态返回。因此,如果ld工具发现两个错误,其退出状态将为 2。
回答by fazineroso
In your situation you got a reference to the missing symbols. But in some situations, ld will not provide error information.
在你的情况下,你得到了对缺失符号的引用。但在某些情况下,ld 不会提供错误信息。
If you want to expand the information provided by ld, just add the following parameters to your $(LDFLAGS)
如果要扩展ld提供的信息,只需在你的$(LDFLAGS)中添加以下参数即可
-Wl,-V
回答by Raivis Rengelis
clrscris not standard C function. According to internet, it used to be a thing in old Borland C.
Is clrscr(); a function in C++?
clrscr不是标准的 C 函数。根据internet的说法,它曾经是旧Borland C中的一个东西。
clrscr(); C++ 中的函数?
回答by Muhammad Kashif Arif
Try running task manager to determine if your program is still running.
尝试运行任务管理器以确定您的程序是否仍在运行。
If it is running then stop it and run it again. the [Error] ld returned 1 exit statuswill not come back
如果它正在运行,则停止它并再次运行它。在[错误] LD返回1个退出状态不会回来
回答by Pratik
Include: #include<stdlib.h>
包括: #include<stdlib.h>
and use System("cls")instead of clrscr()
并使用System("cls")代替clrscr()

