为什么 g++ -MM 选项忽略当前工作目录的包含文件

why g++ -MM option ignore current work dir's include file

本文关键字:包含 文件 当前工作 g++ -MM 选项 为什么      更新时间:2023-10-16

考虑以下示例

myproj/
    main.cc
    test.h

main.cc简单包含测试.h与

#include "myproj/test.h"

当我在myproj的同一目录中运行g++-MM-M时,我得到

$ g++ -MM myproj/main.cc
main.o: myproj/main.cc
$ g++ -M myproj/main.cc
main.o: myproj/main.cc /usr/include/stdc-predef.h myproj/test.h

您将看到-MM选项忽略标头myproj/test.h

问题是myproj/test.h不是系统头,为什么-MM选项忽略它。

在include中,您可以指定相对于当前源文件(在您的情况下为main.cc)的头的路径。你只需要

#include "test.h"
相关文章: