我的 makefile 有什么问题?
我有一个使用以下命令编译的项目:
g++ ALE.cpp -lncurses
这给了我一个 .out 文件。我有以下 Makefile,但它似乎没有正确编辑。
HEADERS = LinkedListNode.h LinkedList.h Classes.h GUI.h Functions.h
default: ale
ale.o: ALE.cpp $(HEADERS)
g++ -c ALE.cpp -o ale.o -lncurses
ale: ale.o
g++ ale.o -o ale
clean:
-rm -f ale.o
-rm -f ale
我得到的错误:
g++ ale.o -o ale
ale.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.text+0x0): first defined here
ale.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata+0x0): first defined here
ale.o: In function `_fini':
/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: first defined here
ale.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.data+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtbegin.o:(.data+0x0): first defined here
ale.o: In function `_init':
/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: first defined here
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
ale.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 ale.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [ale] Error 1
I have this project that that I compile with the following command:
g++ ALE.cpp -lncurses
This gives me a.out file. I have the following Makefile but it seems to not be edited correctly.
HEADERS = LinkedListNode.h LinkedList.h Classes.h GUI.h Functions.h
default: ale
ale.o: ALE.cpp $(HEADERS)
g++ -c ALE.cpp -o ale.o -lncurses
ale: ale.o
g++ ale.o -o ale
clean:
-rm -f ale.o
-rm -f ale
Errors I get:
g++ ale.o -o ale
ale.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.text+0x0): first defined here
ale.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata+0x0): first defined here
ale.o: In function `_fini':
/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: first defined here
ale.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.data+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtbegin.o:(.data+0x0): first defined here
ale.o: In function `_init':
/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: first defined here
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
ale.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 ale.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [ale] Error 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将 -lncurses 移至
ale:
规则中,会发生什么情况,即What happens if you move -lncurses into the
ale:
rule, i.e.在目标文件编译期间使用
-l
是没有意义的。仅当链接您的应用程序时才使用它。因此,您必须将
-lncurses
从第 6 行移至第 9 行。It's make no sense to use
-l
during object file compilation. Use it only when you link your application.So, you have to move
-lncurses
from line 6 to line 9.就像 Foxcub 所说,您为仅编译命令(不需要)提供了链接器选项,并且没有链接器选项(-lncurses)来生成实际需要的可执行命令。
Like foxcub said you are providing a linker option to a compile only command (not needed) and no linker option (-lncurses) to generate executable command where it is actually needed.