本人新手,请教大家,如何编写一个Makefile文件,将当前目录下的所有.c文件编译成.o文件,当前目录下全部.c文件都是子函数,无main函数。
请各位大大们帮忙解答,谢谢!!
4 个解决方案
#1
CC = gcc
CFLAGS = -Wall -O –g
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
CFLAGS = -Wall -O –g
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
#2
搜“跟我一起写Makefile”
#3
这个好像不行,出现下面提示
make: *** No targets. Stop.
#4
已经从高手那得到了比较好的Makefile文件,就分享给大家吧
SRC = ${wildcard *.c}
OBJ = ${patsubst %.c, %.o, $(SRC)}
CFLAGS = -g -Wall
all : $(OBJ) move
$(OBJ):%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@
move :
mv $(OBJ) ../OBJS
clean:
$(RM) $(OBJ) .*.sw?
.PHONY:all clean
SRC = ${wildcard *.c}
OBJ = ${patsubst %.c, %.o, $(SRC)}
CFLAGS = -g -Wall
all : $(OBJ) move
$(OBJ):%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@
move :
mv $(OBJ) ../OBJS
clean:
$(RM) $(OBJ) .*.sw?
.PHONY:all clean
#1
CC = gcc
CFLAGS = -Wall -O –g
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
CFLAGS = -Wall -O –g
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
#2
搜“跟我一起写Makefile”
#3
这个好像不行,出现下面提示
make: *** No targets. Stop.
#4
已经从高手那得到了比较好的Makefile文件,就分享给大家吧
SRC = ${wildcard *.c}
OBJ = ${patsubst %.c, %.o, $(SRC)}
CFLAGS = -g -Wall
all : $(OBJ) move
$(OBJ):%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@
move :
mv $(OBJ) ../OBJS
clean:
$(RM) $(OBJ) .*.sw?
.PHONY:all clean
SRC = ${wildcard *.c}
OBJ = ${patsubst %.c, %.o, $(SRC)}
CFLAGS = -g -Wall
all : $(OBJ) move
$(OBJ):%.o : %.c
$(CC) $(CFLAGS) -c $^ -o $@
move :
mv $(OBJ) ../OBJS
clean:
$(RM) $(OBJ) .*.sw?
.PHONY:all clean