未定义参考主 - collect2:LD返回1退出状态 [英] Undefined reference to main - collect2: ld returned 1 exit status

查看:406
本文介绍了未定义参考主 - collect2:LD返回1退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译程序(称为ES3),但是,当我从终端写的:

I'm trying to compile a program (called es3), but, when I write from terminal:

的gcc -o es3.c ES3

看来这个消息:

/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

我能做什么?

推荐答案

这意味着 es3.c 没有定义函数,并且正试图创建一个可执行文件出来。一个可执行文件需要有一个入口点,因此连接器抱怨。

It means that es3.c does not define a main function, and you are attempting to create an executable out of it. An executable needs to have an entry point, thereby the linker complains.

要只编译成目标文件,使用 -c 选项:

To compile only to an object file, use the -c option:

gcc es3.c -c
gcc es3.o main.c -o es3

以上编译 es3.c 到目标文件,然后编译文件的main.c ,将包含在函数,链接器合并 es3.o main.o中到名为 ES3

The above compiles es3.c to an object file, then compiles a file main.c that would contain the main function, and the linker merges es3.o and main.o into an executable called es3.

这篇关于未定义参考主 - collect2:LD返回1退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆