我的 makefile 有什么问题?

发布于 2024-08-12 05:38:38 字数 2188 浏览 2 评论 0原文

我有一个使用以下命令编译的项目:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没企图 2024-08-19 05:38:38

如果将 -lncurses 移至 ale: 规则中,会发生什么情况,即

ale.o: ALE.cpp $(HEADERS)
    g++ -c ALE.cpp -o ale.o

ale: ale.o
    g++ ale.o -o ale -lncurses

What happens if you move -lncurses into the ale: rule, i.e.

ale.o: ALE.cpp $(HEADERS)
    g++ -c ALE.cpp -o ale.o

ale: ale.o
    g++ ale.o -o ale -lncurses
套路撩心 2024-08-19 05:38:38

在目标文件编译期间使用 -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.

野侃 2024-08-19 05:38:38

就像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文