简体   繁体   English

编译文件时出错 collect2:错误:ld返回1退出状态

[英]Error when compiling file | collect2: error: ld returned 1 exit status

I am having a lot of problem and can't seem to make any sense of what is going on. 我遇到很多问题,似乎无法理解发生了什么。 I am trying to learn C from Learn C The Hard Way , and I am trying to compile the first exercise . 我正在尝试从“ 学习C的艰难方法”中学习C ,并且正在尝试编写第一个练习 When ever I run make I get a huge problem 每当我跑步时,我都会遇到一个大问题

cc     ex1.c   -o ex1

ex1.c: In function ‘main’:

ex1.c:3:5: warning: implicit declaration of function ‘put’ [-Wimplicit-function-declaration]

     put("Hello world.");
     ^

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../libc.so when searching for -lc

/usr/bin/ld: skipping incompatible /lib/libc.so when searching for -lc

/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc

/usr/bin/ld: cannot find -lc

collect2: error: ld returned 1 exit status

<builtin>: recipe for target 'ex1' failed


make: *** [ex1] Error 1

any help would be wonderful 任何帮助都会很棒

The first error is clear; 第一个错误很明显; there is no declaration for a function called put() . 没有名为put()的函数的声明。 This is either because 这是因为

  • you have mistyped the function name, 您输入了错误的函数名称,
  • or because you have failed to provide a declaration either directly of via a header file containing the declaration. 或者由于您未能直接通过包含该声明的头文件提供声明。

In this case if the code you were attempting to compile is from this exercise then look at it again - it clearly differs from your code (ie the first of the possibilities listed above). 在这种情况下,如果您尝试编译的代码来自此练习 ,请再次查看-它显然与您的代码不同(即,上面列出的第一种可能性)。 However even then you would get the same error; 但是即使那样,您仍然会遇到相同的错误; read further in the exercise and you will see that the author has deliberately omitted the header file in order to illustrate the need for the specific library header file. 在练习中进一步阅读,您将看到作者故意省略了头文件,以说明对特定库头文件的需要。 The reason you get the warning without the suggested -Wall command line option is probably because you are using a newer version of the compiler than the author. 没有建议的-Wall命令行选项而得到警告的原因可能是因为您使用的是比作者新的编译器版本。 To be honest from what little I have seen of "Learn C the Hard Way", I would steer clear of it. 老实说,从我对“艰难学习C”的了解中,我将避免使用它。

The second issue is one of your linker being unable to find an appropriate version of the standard C library to link to your code. 第二个问题是您的链接器之一无法找到合适的标准C库版本来链接到您的代码。 Compiling C code in Linux is normally straightforward; 在Linux中编译C代码通常很简单。 most distributions come with GCC already correctly installed and working; 大多数发行版都随附已正确安装并可以正常工作的GCC; your's appears to be horribly broken. 您的手机似乎坏了。 You may want to repair your toolchain installation. 您可能需要修复工具链安装。 You may have installed multiple incompatible toolchains. 您可能已经安装了多个不兼容的工具链。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM