makefile文件 - 编译所有的C文件一次 [英] makefiles - compile all c files at once

查看:134
本文介绍了makefile文件 - 编译所有的C文件一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用GCC整个程序优化实验。要做到这一点我必须一次通过所有的C-文件编译器前端。但是,我用的makefile自动编译过程中,我不是专家,当涉及到的makefile魔术。

我应该如何修改Makefile,如果我想只用一个电话给GCC编译(甚至链接)?

有关参考 - 我生成文件看起来是这样的:

  LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -WallOBJ = 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 $ @测试:$(O​​BJ)
    GCC -o $ @ $ ^ $(CFLAGS)$(LIBS)


解决方案

  LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall#应相当于你的C文件列表,如果你不选择建
SRC = $(通配符的* .c)测试:$(SRC)
    GCC -o $ @ $ ^ $(CFLAGS)$(LIBS)

I want to experiment with GCC whole program optimizations. To do so I have to pass all C-files at once to the compiler frontend. However, I use makefiles to automate my build process, and I'm not an expert when it comes to makefile magic.

How should I modify the makefile if I want to compile (maybe even link) using just one call to GCC?

For reference - my makefile looks like this:

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)

解决方案

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)

这篇关于makefile文件 - 编译所有的C文件一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆