Search code examples
c++preprocessor

Using clang or g++/gcc to print preprocessed code without including files from system paths


currently I'd like to debug my includes. To do this I want to get the preprocessed code, but without any system header files - just my own code.

I tried it with flag "-E" and "-nostdinc". But then I get errors that for example <string> is missing. How to disable such preprocessing errors?


Solution

  • (It's not really an answer - just a "hack")

    To solve this I created a text file with all system headers by:

    rem my GCC STL-PATH
    cd Z:\usr\include\c++\10
    
    dir /b > F:\DummySTL\files.txt
    

    Then I executed the following line of code:

    for /f "delims=" %F in (files.txt) do copy nul "%F"
    

    This creates an empty text file for every line in the file. Now I can call gcc or clang just with:

    -isystem"F:\DummySTL"