我想试验一下GCC的整个程序优化。为此,我必须一次将所有C文件传递给编译器前端。然而,我使用makefile来自动化我的构建过程,当涉及到makefile魔术时,我并不是专家。
如果我只想使用一次对GCC的调用来编译(甚至是链接),我应该如何修改makefile?
作为参考-我的makefile看起来像这样:
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
OBJ = 64bitmath.o \
monotone.o \
node_sort.o \
planesweep.o \
triangulate.o \
prim_combine.o \
welding.o \
test.o \
main.o
%.o : %.c
gcc -c $(CFLAGS) $< -o $@
test: $(OBJ)
gcc -o $@ $^ $(CFLAGS) $(LIBS)发布于 2008-10-04 15:00:59
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
# Should be equivalent to your list of C files, if you don't build selectively
SRC=$(wildcard *.c)
test: $(SRC)
gcc -o $@ $^ $(CFLAGS) $(LIBS)发布于 2010-11-02 11:47:53
SRCS=$(wildcard *.c)
OBJS=$(SRCS:.c=.o)
all: $(OBJS)发布于 2014-02-03 21:15:49
您需要删除后缀规则(%.o:%.c)以支持大爆炸规则。如下所示:
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
OBJ = 64bitmath.o \
monotone.o \
node_sort.o \
planesweep.o \
triangulate.o \
prim_combine.o \
welding.o \
test.o \
main.o
SRCS = $(OBJ:%.o=%.c)
test: $(SRCS)
gcc -o $@ $(CFLAGS) $(LIBS) $(SRCS)如果您要尝试使用GCC的全程序优化,请确保在上面的CFLAGS中添加适当的标志。
在阅读这些标志的文档时,我也看到了关于链接时间优化的注释;您也应该研究这些。
https://stackoverflow.com/questions/170467
复制相似问题