More GCC link time issues: undefined reference to main

淺唱寂寞╮ 提交于 2019-12-03 15:43:17

In the makefile:

hello: main.o functions.o
    gcc -o main.o functions.o

should be:

hello: main.o functions.o
    gcc -o hello main.o functions.o

As it stands, you are linking functions.o, but not main.o, and producing an output executable called main.o, which is overwriting your existing main.o.

Shouldn't

hello: main.o functions.o
    gcc -o main.o functions.o

be

hello: main.o functions.o
    gcc -o hello main.o functions.o

As Bigbohne suggests, gcc is trying to link in the standard runtime library. Try adding the -nostdlib option to your gcc call:

gcc -nostdlib -o hello main.o functions.o

I think that has something to do with the Runtime library the gcc is linking at the end.

And in this library there already is a "_start".

I think you have to compile without "std library". but than you wont have printf,getchar and all the other useful stuff.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!