强制生成文件生成源两次
force makefile to build sources twice
我有以下制作文件:
all: a.out b.out
.PHONY: gen_hdr1
gen_hdr1:
#call script 1 that generates x.h
rm a.o #try to force rebuild of a.cpp
.PHONY: gen_hdr2
gen_hdr2:
#call script 2 that generates x.h
rm a.o #try to force rebuild of a.cpp
b.out: gen_hdr2 a.o
g++ -o b.out a.o
a.out: gen_hdr1 a.o
g++ -o a.out a.o
*.o : *.cpp
g++ -c $< -o $@
A.cpp包括X X.H
我想做什么:
- 删除 a.o(如果存在)
- 为应用 A 生成 x.h
- 编译 A.cpp
- 构建应用 A
- 删除 a.o(如果存在)
- 为应用 B 生成 x.h
- 再次编译 A.cpp
- 构建应用 B
运行生成文件的输出为:
#call script 1 that generates x.h
rm -f a.o #try to force rebuild of a.cpp
g++ -c -o a.o a.cpp
g++ -o a.out a.o
#call script 2 that generates x.h
rm -f a.o #try to force rebuild of a.cpp
g++ -o b.out a.o
g++: a.o: No such file or directory
g++: no input files
make: *** [b.out] Error 1
基本上,构建应用程序 B 时找不到 a.o。如何强制制作系统重建它?
对于
此类问题,很好的解决方案是使用单独的构建对象文件夹,每个目标多一个子文件夹。
因此,您将得到类似以下内容:
build/first/a.o: src/a.cpp gen/a.h
# Do you stuff in here
gen/a.h:
# Generate you .h file if needed
build/second/a.o: src/a.cpp gen/a.h
# Same thing
使用此解决方案,您将在构建文件夹中拥有所有构建对象,因此 clean 命令稍微简单一些:
clean:
rm -rf build/*
rm -rf gen/*
rm -rf bin/*
您唯一应该确保的是目录在构建之前就存在,但这不是要做的工作:)
如果你必须生成两个版本的a.h,你可以使用相同的设计(gen/first和gen/second文件夹)。
希望对您有所帮助,如果我错过了什么,请告诉我
相关文章:
- C++两次从文件保存对象读取多重继承
- 带有文件结束函数的 while 循环重复输出文件中的最后一个数字两次
- 在循环工作时,首先将两个文件读为向量,但仅次于迭代一次
- 如何使用预处理器指令包含两次具有不同代码的文件?
- 使用字符串流逐行读取文件两次
- C OOP,读取文件的问题,EOF使用了两次,排行榜
- Qfiledialog:文件夹名称在Windows下方出现两次
- 是否值得两次通过文件进行迭代,以创建最小的数据结构
- 为什么输入文件的最后一行运行两次?
- 为什么在这里对c++输入文件流进行两次检查
- 锁定文件,避免使用相同的过程以访问两次
- 尽管 #ifndef,但包含两次头文件
- CppUnit 和 CMake:.cpp文件被编译两次
- 正在从文件中读取最后两次出现的内容
- 流将所有内容写入我的文件两次
- NodeJS 文件系统 监视抛出事件两次或更多次
- 我的文件正在输出到屏幕两次 C++
- 文件在add_custom_command后source_group中添加了两次
- 程序写入记录在 C++ 的二进制文件中两次
- C++ cout 字符'return'文件中的字符出现两次