Creating Makefile that compiles multiple C files for use in Minix

爷,独闯天下 提交于 2020-01-06 12:50:31

问题


I am trying to create a Makefile that compiles multiple C files for use in Minix. How would I change the Makefile so that it compiles multiple files at the same time? Below is the current state of my Makefile.

CFLAGS  = -D_POSIX_SOURCE
LDFLAGS =
CC      = cc
LD      = cc

PROG    = test

OBJS    = test.o

$(PROG): $(OBJS)
        $(LD) $(LDFLAGS) $(OBJS) -o $(PROG)

clean:
        rm -rf $(PROG) $(OBJS)

I thought I could just list the other programs after PROG and OBJS such as

PROG   = test test2

OBJS   = test.o test2.o

but that didn't work. Any ideas? Thanks in advance.


回答1:


Split it up this way:

PROG1 = test 
PROG2 = test2
OBJ1 = test.o
OBJ2 = test2.o


$(PROG1): $(OBJ1) 
          $(LD) $(LDFLAGS) $(OBJ1) -o $(PROG1)
$(PROG2): $(OBJ2) 
          $(LD) $(LDFLAGS) $(OBJ2) -o $(PROG2)

etc



来源:https://stackoverflow.com/questions/19213584/creating-makefile-that-compiles-multiple-c-files-for-use-in-minix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!