我试图编译一个程序(称为es3),但当我从终端写入时:
gcc es3.c -o 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),但当我从终端写入时:
gcc es3.c -o 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
没有定义main
函数,您正试图用它创建一个可执行文件.可执行文件需要有一个入口点,因此链接器会抱怨.
要仅编译为对象文件,请使用-c
选项:
gcc es3.c -c
gcc es3.o main.c -o es3
上述代码将es3.c
编译为目标文件,然后编译将包含main
函数的文件main.c
,并且链接器将es3.o
和main.o
合并为名为es3
的可执行文件.