Skip to content
systemcoding.dev
Toolchains

Print GCC's include search path with gcc -xc -E -v -

Print the exact directories GCC 14 searches for headers by preprocessing empty input with gcc -xc -E -v -, with no source file needed.

1 min read
Summarize in AI

When an #include resolves to the wrong header, guessing at -I flags wastes time. Ask the preprocessor instead: GCC 14.2 prints its search list when you run it verbosely over empty input, so no source file has to exist.

Shell
gcc -xc -E -v - < /dev/null
Text
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/14/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

The list goes to stderr, which is why a pipe into grep seems to find nothing until you add 2>&1. The first group, for quoted includes, is empty here because stdin has no directory of its own; with a real file, that file's directory comes first. Your paths will differ by distribution and by the --with-sysroot GCC was built with. Change -xc to -xc++ to see the C++ list, which adds the libstdc++ directories ahead of the C ones. Any -I, -isystem or --sysroot flags you add to the command show up in the output, so it is also how you check what a build system really passes. The Preprocessor Options page covers -v and the include flags.

Taggedcgcc
Share

More snippets

Systems Programming

Get the page size with sysconf(_SC_PAGESIZE)

Read the memory page size at run time with sysconf(_SC_PAGESIZE) instead of hard-coding 4096, which is wrong on arm64 kernels built with 16K or 64K pages.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.