如何在 gcc 和 make 中使用预编译头?

发布于 2024-12-11 23:12:01 字数 474 浏览 0 评论 0原文

我有一个在调用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛时过境迁 2024-12-18 23:12:01

添加命令怎么样

sed -e 's/.h /.h.pch /g' -e 's/.h$/.h.pch/' $*.d > $*.dd

(如果您愿意,可以适当修改 foo.d。)

How about adding a command

sed -e 's/.h /.h.pch /g' -e 's/.h$/.h.pch/' $*.d > $*.dd

(You can modify foo.d in place if you prefer.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文