码迷,mamicode.com
首页 > 编程语言 > 详细

hello_Makefile_c++

时间:2015-11-20 21:24:32      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

1、错误:

hello.o: In function `_start‘:

(.text+0x0): multiple definition of `_start‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here

hello.o:(.rodata+0x0): multiple definition of `_fp_hw‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here

hello.o: In function `_fini‘:

(.fini+0x0): multiple definition of `_fini‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here

hello.o:(.rodata+0x4): multiple definition of `_IO_stdin_used‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here

hello.o: In function `__data_start‘:

(.data+0x0): multiple definition of `__data_start‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here

hello.o: In function `__data_start‘:

(.data+0x4): multiple definition of `__dso_handle‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here

hello.o: In function `_init‘:

(.init+0x0): multiple definition of `_init‘

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here

/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__‘

hello.o:(.dtors+0x4): first defined here

/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.

/usr/bin/ld: error in hello.o(.eh_frame); no .eh_frame_hdr table will be created.

collect2: ld returned 1 exit status

make: *** [hello] Error 1

原因:

经测试:单独编译hello.cpp的时候不会报上面的错误,而使用Makefile时会报出上面的错误,说明是Makefile的原因;

原版的Makefile是:

hello:hello.o

        g++ -o hello hello.o

hello.o:hello.cpp hello.h

        g++ -o hello.o hello.cpp

clean:

        rm hello.o hello a.out

而修改后的Makefile为:

hello:hello.o

        g++ -o hello hello.o

hello.o:hello.cpp hello.h

        g++ -c hello.cpp

clean:

        rm hello.o hello a.out

导致的原因是:参数-c是生成.o文件的(只编译,不连接),-o是确定生成文件名称;

感悟:

Makefile对文件的编译是分步进行的:

a)         –c(只编译不连接);

b)        连接,生成执行文件;

2、错误:

/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start‘:
(.text+0x18): undefined reference to `main‘
collect2: ld returned 1 exit status

原因:一般出现这个问题是main打错了,或者没有写main,或者main被其他子函数包含了,注意检查下就好,我之前粗心,出现过这个问题,但是其他的文件gcc编译链接可以通过,就这个不能。

hello_Makefile_c++

标签:

原文地址:http://www.cnblogs.com/Joker714/p/4982160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!