GCC のデフォルトのインクルードディレクトリは何ですか? 質問する

GCC のデフォルトのインクルードディレクトリは何ですか? 質問する

gcc を使用して非常に単純なソース ファイルをコンパイルする場合、stdio や stdlib などの標準インクルード ファイルへのパスを指定する必要はありません。

GCC はどのようにしてこれらのファイルを見つけるのでしょうか?

Does it have the /usr/include path hardwired inside, or it will get the paths from other OS components?

ベストアンサー1

In order to figure out the default paths used by gcc/g++, as well as their priorities, you need to examine the output of the following commands:

  1. For C:
echo | gcc -xc -E -v -
  1. For C++:
echo | gcc -xc++ -E -v -

The credit goes to Qt Creator team.

Here's a breakdown of the flags:

  • -x selects the language, C or C++ respectively

  • -E makes gcc to run the preprocessor only, so no compilation takes place

  • -v prints all the commands run, which is the key to dumping the standard paths

  • - is the "input file" to preprocess, as a convention - stands for stdin (or stdout, depending on the context);

    echo | feeds an empty string to gcc so effectively we preprocess an empty file generated on the fly

Here's a nice explaining it in more detail: https://explainshell.com/explain?cmd=echo+%7C+gcc+-xc+-E+-v+-

おすすめ記事