I'd advise thinking of your makefile as code (since it is) and follow the standard advice to avoid repeating yourself.
It looks like you also have the flags a bit wrong. -m32
is a compiler flag. -ldl
is a linker flag. If you're going to build for 32 bits, you need to tell both the compiler and the linker to built 32-bit files. No guarantee, but I think you want something on this general order:
CFLAGS = -m32
LFLAGS = -melf_i386 -ldl
mem_1: mem_1.o memlayout.o
$(LD) $(LFLAGS) -o mem_1 mem_1.o memlayout.o
mem_2: mem_2.o memlayout.o
$(LD) $(LFLAGS) -o mem_2 mem_2.o memlayout.o
mem_3: mem_3.o memlayout.o
$(LD) $(LFLAGS) -o mem_3 mem_3.o memlayout.o
# You probably don't really need this--`make` will usually have it built-in:
.c.o:
$(CC) -c $(CFLAGS) $<
Note: I'm old, so this is a sort of old-fashioned Makefile. Gnu recommends doing things a bit differently, but this should still work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…