makefile用不同的标志编译多个源 [英] makefile to compile multiple sources, with different flags
本文介绍了makefile用不同的标志编译多个源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下makefile:
I have the following makefile:
CC = gcc
SRC = source1.c
EXE = source1
FLAGS = -fopenmp
all: $(src)
$(CC) -o $(EXE) $(SRC) $(FLAGS)
clean:
rm $(EXE)
如何修改我可以使用多个源,其中一些用标志-fopenmp编译,其中一些编译没有。非常感谢。
How can I modify it so I can use multiple sources, some of them compiled with the flag -fopenmp, some of them compiled without. Thanks a lot.
推荐答案
这应该让你开始:注意 -fopenmp
只为source2.c添加
This should get you started: Note how -fopenmp
gets added just for source2.c
CC=gcc
SRC=source1.c source2.c
OBJ=$(patsubst %.c,%.o,$(SRC))
EXE=source1
FLAGS= -g -O2
source2.o: FLAGS+=-fopenmp
all: $(EXE)
$(EXE): $(OBJ)
$(CC) -o $@ $^ $(FLAGS)
%.o: %.c
$(CC) -c -o $@ $^ $(FLAGS)
clean:
rm $(EXE)$
输出 make -Bsn
:
gcc -o source1.o source1.c -g -O2
gcc -o source2.o source2.c -g -O2 -fopenmp
gcc -o source1 source1.o source2.o -g -O2
这篇关于makefile用不同的标志编译多个源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文