最近在VSCode上跑C++代码,当编译的时候出现了题目中的问题,在CSDN上搜到的解决方案可谓是“天下一大抄”,这抄那里,那抄这里,全都一样,而且没有解释明白这个报错是什么意思,光说了一些出现该提醒可能的原因(且提到的原因我感觉驴唇不对马嘴)。所以逼得我去****,用Google搜索了一下,结果第一个回答就解决了疑惑。下面分享给没法****的朋友们。
简单来说,collect2 error ld returned 1 exit status提示出现之前,一般在上面几行都会有其他报错,而collect2 error ld returned 1 exit status所反映的只是其之前一共出现了多少个错误,真正的错误是在其上面出现的那些报错。比如,没有错误,会提示collect2 error ld returned 0 exit status;有两个报错,会提示collect2 error ld returned 2 exit status。所以,真正要解决的是在collect2 error ld returned 1 exit status提示出现之前的那些报错提醒。
以下是Google回答的原文:
The ld returned 1 exit status error is the consequence of your previous errors as 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. Various tools may be running while creating a program 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.
In many cases tools return as the exit status the number of errors they encountered. So if the old tool finds two errors, its exit status would be 2.
————————————————
版权声明:本文为CSDN博主「间歇努力为了持续躺平」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45055622/article/details/126634000