c++ - 我的 makefile 有什么问题?

标签 c++ makefile compiler-construction

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

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

最佳答案

如果将 -lncurses 移动到 ale: 规则中会发生什么,即

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

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

关于c++ - 我的 makefile 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1777588/

相关文章:

c++ - 在Dom解析器中找不到作者

c++ - glm 旋转和平移

c++ - 自定义 HashMap 在 Linux 上使用 gcc 给出编译错误

android - 如何做一个android mm清洁?

c# - 在运行时使用类似 C# 的脚本

c# - Visual Studio 2010基于目标框架的编译条件

c++ - 从文件中读取会产生意外的输出

使用 eval 时 Makefile 规则不是目标

javascript - 从 git 存储库构建手写笔

C++ 编译器 'shallow' 拷贝和赋值