Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been reading so many make guide but I still cant make it work. I'm trying to create a makefile that creates different programs, each program has its own source file (.c) but they all use the same header file (.h) nad all the files are in the same directory.

For now i have this:

CC   = gcc
CFLAGS   = -std=c99 -g -c -Wall
LFLAGS   = -std=c99 -g -c -Wall

OBJS    = nivel1.o nivel2.o nivel3.o nivel4.o nivel5.o nivel6.o my_shell.o
OUT = nivel1,nivel2,nivel3,nivel4,nivel5,nivel6,my_shell

OBJS0   = nivel1.o
SOURCE0 = nivel1.c
HEADER0 = my_shell.h
OUT0    = nivel1

OBJS1   = nivel2.o
SOURCE1 = nivel2.c
HEADER1 = my_shell.h
OUT1    = nivel2

OBJS2   = nivel3.o
SOURCE2 = nivel3.c
HEADER2 = my_shell.h
OUT2    = nivel3

OBJS3   = nivel4.o
SOURCE3 = nivel4.c
HEADER3 = my_shell.h
OUT3    = nivel4

OBJS4   = nivel5.o
SOURCE4 = nivel5.c
HEADER4 = my_shell.h
OUT4    = nivel5

OBJS5   = nivel6.o
SOURCE5 = nivel6.c
HEADER5 = my_shell.h
OUT5    = nivel6

OBJS6   = my_shell.o
SOURCE6 = my_shell.c
HEADER6 = my_shell.h
OUT6    = my_shell

all: nivel1 nivel2 nivel3 nivel4 nivel5 nivel6 my_shell

nivel1: $(OBJS0) $(LFLAGS)
    $(CC) -g $(OBJS0) -o $(OUT0)

nivel2: $(OBJS1) $(LFLAGS)
    $(CC) -g $(OBJS1) -o $(OUT1)

nivel3: $(OBJS2) $(LFLAGS)
    $(CC) -g $(OBJS2) -o $(OUT2)

nivel4: $(OBJS3) $(LFLAGS)
    $(CC) -g $(OBJS3) -o $(OUT3)

nivel5: $(OBJS4) $(LFLAGS)
    $(CC) -g $(OBJS4) -o $(OUT4)

nivel6: $(OBJS5) $(LFLAGS)
    $(CC) -g $(OBJS5) -o $(OUT5)

my_shell: $(OBJS6) $(LFLAGS)
    $(CC) -g $(OBJS6) -o $(OUT6)

nivel1.o: nivel1.c
    $(CC) $(FLAGS) nivel1.c -std=c99

nivel2.o: nivel2.c
    $(CC) $(FLAGS) nivel2.c -std=c99

nivel3.o: nivel3.c
    $(CC) $(FLAGS) nivel3.c -std=c99

nivel4.o: nivel4.c
    $(CC) $(FLAGS) nivel4.c -std=c99

nivel5.o: nivel5.c
    $(CC) $(FLAGS) nivel5.c -std=c99

nivel6.o: nivel6.c
    $(CC) $(FLAGS) nivel6.c -std=c99

my_shell.o: my_shell.c
    $(CC) $(FLAGS) my_shell.c -std=c99

clean:
    rm -f $(OBJS) $(OUT)

I've tried changing many things but nothing gets it to work, any help would be appreciated! PD: I need it to be std c99.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
347 views
Welcome To Ask or Share your Answers For Others

1 Answer

nivel1: $(OBJS0) $(LFLAGS)
    $(CC) -g $(OBJS0) -o $(OUT0)

is wrong. That is why make complains. You specified a dependance on $(LFLAGS) but that is not a file or a target, that is just a flag definition used at compile-time. You probably want:

nivel1: $(OBJS0)
    $(CC) $(LFLAGS) -g $(OBJS0) -o $(OUT0)

---EDIT---(suggested by Kaylum)

LFLAGS has a wrong value. Since this command is a linking phase, neither -std=c99, -c nor -Wall are usable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...