linux - crt1.o : In function `_start' : - undefined reference to `main' in Linux

标签 linux program-entry-point undefined-reference

我正在将一个应用程序从 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/

相关文章:

java - 在 linux 上设置类路径以运行 java 程序

linux - sed:用一个下划线替换一系列点

c - gcc 和 glibc 版本

没有 main 方法的 C# 类

c++ - 可以通过这种方式声明一个全局对象类吗?

c++ - g++ "undefined reference"错误

linux - 如何在unix中显示文件第n行的所有行

java 101,我如何计算传递给 main 的参数数量?

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?