Search code examples
clangclang++llvm-clang

Can someone explain how this Clang argument working?


While searching Google, I discovered that this command below can show the clang default include path, but how does it work? I've checked help page and know the meaning of each argument, but I can't understand how these arguments work together, especially the - between c++ and -v.

clang++ -E -x c++ - -v < /dev/null

Solution

  • clang++ is the name of the program to run.

    -E is an option telling clang to stop after preprocessing (i.e. it won't run the actual compiler or linker, just the preprocessor).

    -x c++ is a language override option. It tells clang that the input file should be interpreted as C++ source code (the default behavior is to detect the file type from the extension, such as .cpp or .o).

    -v means "verbose", I think. It tells clang to print extra information during compilation.

    - is not an option; it's the name of the input file. As with many other tools, an input filename of - tells clang to read from its standard input instead.

    Finally < /dev/null is an I/O redirection. It tells the shell to connect clang's standard input to /dev/null (effectively an empty file).

    The last two parts are a bit roundabout: Instead of telling clang to read from stdin and redirecting stdin to /dev/null, we could've just told clang to read from /dev/null directly:

    clang++ -E -x c++ -v /dev/null
    

    Anyway, the point is to preprocess (-E) an empty file (/dev/null) as if it were C++ code (-x c++).