怎么解决?? collect2:错误:ld在Debian GCC终端中返回1退出状态

时间:2018-07-15 11:27:52

标签: linux gcc debian

我的文件名为hello.c

#include<stdio.h>
int main(void)
{
  printf("Hello World!");
  return 0;
}

我给出的命令是:

$ gcc hello.c -o hello
$ gcc ./hello

终端输出为:

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

可以请任何人帮助我吗? 我使用:

gcc version 7.2.0 (Debian 7.2.0-20)

1 个答案:

答案 0 :(得分:0)

$ gcc hello.c -o hello
$ gcc ./hello

假设您尝试使用第二个命令运行它,那么它应该只是./hello(换句话说,从一开始就去掉gcc)。

您要尝试的是在已经可以运行的状态下编译/链接已经从源代码编译的可执行文件