如何在 gcc 和 make 中使用预编译头?
我有一个在调用 g++ 时使用 -MMD -MP 选项的 make 文件。这将创建看起来像这样的 .d 依赖文件:
blah.o: header1.h header2.h
现在,我正在尝试添加预编译头支持,并且希望有一个类似于以下的规则:
$(OUT_DIR)/%.h.pch: $(SRC_DIR)/%.h
g++ -c $< -o $@
然后我希望 .d 文件看起来像这样:
blah.o: header1.h.pch header2.h.pch
这样,.o 文件依赖于预编译头,而预编译头又依赖于头。这样我就可以确保在编译依赖的 .cpp 文件之前创建任何预编译头。我的问题是我无法找到一种方法让 g++ 创建具有 *.pch 扩展名的依赖文件。我尝试的所有操作总是产生典型的 .h 扩展名。有人有什么想法吗?
I have a make file that uses the -MMD -MP options when invoking g++. This creates the .d dependency files that look something like this:
blah.o: header1.h header2.h
Now, I'm trying to add precompiled header support, and would like to have a rule similar to:
$(OUT_DIR)/%.h.pch: $(SRC_DIR)/%.h
g++ -c lt; -o $@
and then I'd like the .d files to look like this:
blah.o: header1.h.pch header2.h.pch
That way the .o files are dependent on the precompiled headers, and the precompiled headers depend on the headers. That way I can be sure that any precompiled headers are created BEFORE the dependent .cpp file is compiled. My problem is I can't figure out a way to have g++ create dependency files that have the *.pch extensions. Everything I try always produces the typical .h extensions. Anybody have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加命令怎么样
(如果您愿意,可以适当修改
foo.d
。)How about adding a command
(You can modify
foo.d
in place if you prefer.)