例如makefile文件构建简单的C项目重新编译时标题更改 [英] Example makefile for building simple c project recompiling when headers change
本文介绍了例如makefile文件构建简单的C项目重新编译时标题更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人有一个完整的makefile,可以做到以下几点:
- 重新生成项目,如果一个头文件的更改
- 的cpp文件在makefile文件中列出
- 的头文件在Makefile中未列出
- 的头文件都不允许有比cpp文件不同的名称
- 某些cpp文件中没有头文件
我已经看到搞清楚如何使化妆工具找出头的依赖关系的指令,但没有这些指令提供任何远程类似工作的例子。一个简单的例子如下:main.cpp中C1.cpp C1.h C2.cpp C2.h
解决方案
CXX = g ++的对象:= main.o中C1.o C2.o所有:$(对象)%的.o:%的.cpp
$(CXX)$(CPPFLAGS)-Wall -c -MMD $< -o $ @-include * .D
Does anyone have a complete makefile that can do the following:
- Rebuilds the project if a HEADER file changes
- The cpp files are listed in the makefile
- The header files are NOT listed in the makefile
- The header files are allowed to have different names than the cpp files
- Some of the cpp files do not have header files
I have seen instructions for figuring out how to make the make tool figure out header dependencies, but none of these instructions provide anything remotely resembling a working example. A simple example would be as follows: main.cpp C1.cpp C1.h C2.cpp C2.h
解决方案
CXX = g++
OBJECTS := main.o C1.o C2.o
all: $(OBJECTS)
%.o : %.cpp
$(CXX) $(CPPFLAGS) -Wall -MMD -c $< -o $@
-include *.d
这篇关于例如makefile文件构建简单的C项目重新编译时标题更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文