我正在将一个应用程序从 Solaris 移植到 Linux
链接的目标文件没有定义 main()。但是编译和链接在 Solaris 中正确完成并生成了可执行文件。在 Linux 中我得到这个错误
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
我的问题是,我不能包含新的 .c/.o 文件,因为它是一个庞大的应用程序并且已经运行了多年。我怎样才能摆脱这个错误?
makefile 的代码摘录:
RPCAPPN = api
LINK = cc
$(RPCAPPN)_server: $(RPCAPIOBJ)
$(LINK) -g $(RPCAPIOBJ) -o $(RPCAPPN)_server $(IDALIBS) $(LIBS) $(ORALIBS) $(COMMONLIB) $(LIBAPI) $(CCLIB) $(THREADLIB) $(DBSERVERLIB) $(ENCLIB)
最佳答案
尝试将 -nostartfiles
添加到您的链接器选项中,即
$(LINK) -nostartfiles -g ...
来自 gcc documentation :
-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.
这会导致 crt1.o
不被链接(默认情况下它通常是链接的) - 通常仅在您实现自己的 _start
代码时使用。
关于linux - crt1.o : In function `_start' : - undefined reference to `main' in Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11116399/