我从移植Solaris到Linux应用
这两篇文章没有一个主要的目标文件()定义。 但是,编译和链接是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文件和已经运行了多年。 我怎样才能摆脱这种错误的?
生成文件的代码extractes:
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文档 :
-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
代码。
-shared
当你编译一个链接选项,则必须使用.so
努力打造与提升一个新的测试项目时,我也有类似的结果,而事实证明,我错过了一个声明:
#define BOOST_TEST_MODULE <yourtestName>
编译Fortran程序是曾在联C ++组件时,我也有类似的结果。在我的情况,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
解决的办法是增加
set_target_properties(myprogram PROPERTIES LINKER_LANGUAGE Fortran)
到的CMakeLists.txt,以便make
打印出来:
[100%] Linking Fortran executable myprogram
[100%] Built target myprogram