How do I run the preprocessor on local headers only?

前端 未结 4 2093
陌清茗
陌清茗 2020-12-03 17:12

I want the preprocessor to read in the includes of local headers, but ignore the includes of system headers. To put it another way, how do I get the preprocessor to skip ov

4条回答
  •  失恋的感觉
    2020-12-03 17:33

    You can protect the system includes with a temporarily included comment, keep comments in the preprocessor output (-CC) and then remove the protectors again.

    Something like:

    sed -i 's%#include <%//PROTECTED #include <%g' $(find . -name '*.[hc]pp')
    g++ -E -P -CC main.cpp -o new_main.cpp
    sed -i 's%//PROTECTED %%g' new_main.cpp
    

    Since you are modifying the source files, it might be a good idea to create a copy first and work on those copies instead. Plus some other details, but the above is the general idea you need.

提交回复
热议问题