crt1.o:在函数‘_start’中:-在Linux中未定义对‘main’的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11116399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
crt1.o: In function `_start': - undefined reference to `main' in Linux
提问by Blackforest
I am porting an application from Solaris to Linux
我正在将应用程序从 Solaris 移植到 Linux
The object files which are linked do not have a main() defined. But compilation and linking is done properly in Solaris and executable is generated. In Linux I get this error
链接的目标文件没有定义 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'
My problem is, I cannot include new .c/.o files since its a huge application and has been running for years. How can I get rid of this error?
我的问题是,我不能包含新的 .c/.o 文件,因为它是一个巨大的应用程序并且已经运行了多年。我怎样才能摆脱这个错误?
Code extractes of makefile:
makefile 的代码摘录:
RPCAPPN = api
LINK = cc
$(RPCAPPN)_server: $(RPCAPIOBJ)
$(LINK) -g $(RPCAPIOBJ) -o $(RPCAPPN)_server $(IDALIBS) $(LIBS) $(ORALIBS) $(COMMONLIB) $(LIBAPI) $(CCLIB) $(THREADLIB) $(DBSERVERLIB) $(ENCLIB)
采纳答案by Paul R
Try adding -nostartfiles
to your linker options, i.e.
尝试添加-nostartfiles
到您的链接器选项,即
$(LINK) -nostartfiles -g ...
From the gcc documentation:
从gcc 文档:
-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.
This causes crt1.o
not to be linked (it's normally linked by default) - normally only used when you implement your own _start
code.
这会导致crt1.o
不被链接(默认情况下通常是链接的) - 通常仅在您实现自己的_start
代码时使用。
回答by user2783604
-shared
link option must be used when you compile a .so
-shared
编译时必须使用链接选项 .so
回答by serup
I had similar result when trying to build a new test project with boost, and it turned out that I was missing one declaration :
我在尝试使用 boost 构建一个新的测试项目时得到了类似的结果,结果我遗漏了一个声明:
#define BOOST_TEST_MODULE <yourtestName>
回答by Bastian
I had a similar result when compiling a Fortran program that had C++ components linked in. In my case, CMake failed to detect that Fortran should be used for the final linking. The messages returned by make
then ended with
在编译链接了 C++ 组件的 Fortran 程序时,我得到了类似的结果。就我而言,CMake 未能检测到 Fortran 应该用于最终链接。然后返回的消息make
以
[100%] Linking CXX executable myprogram
/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
make[3]: *** [myprogram] Error 1
make[2]: *** [CMakeFiles/myprogram.dir/all] Error 2
make[1]: *** [CMakeFiles/myprogram.dir/rule] Error 2
make: *** [myprogram] Error 2
The solution was to add
解决方案是添加
set_target_properties(myprogram PROPERTIES LINKER_LANGUAGE Fortran)
to the CMakeLists.txt, so that make
prints out:
到 CMakeLists.txt,以便make
打印出:
[100%] Linking Fortran executable myprogram
[100%] Built target myprogram