Where gcc search include?

Is command: `gcc -print-prog-name=cc1` -v
1. what are meaning of apostrophes?
2. This command not ends. I must echo | `gcc -print-prog-name=cc1` -v
3. My result is
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include

It means that prefering is /usr/lib/gcc/x86_64-linux-gnu/9/include under /usr/local/include under /usr/include ?

are better ways but other list:
gcc -E -Wp,-v -xc /dev/null
g++ -E -Wp,-v -xc++ /dev/null
Last edited on
1.
man bash wrote:
Command Substitution
Command substitution allows the output of a command to replace the command name. There are two forms:

$(command)
or
`command`

Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).

In other words, your runs first gcc -print-prog-name=cc1
The output of that command probably looks something like /usr/lib/gcc/x86_64-linux-gnu/9/cc1
Therefore, the "actual command" that you run is /usr/lib/gcc/x86_64-linux-gnu/9/cc1 -v

2. The command apparently reads stdin until it encounters EOF. Then it completes. Similar to:
1
2
3
4
5
6
7
#include <iostream>
int main() {
  char c {};
  while ( std::cin >> c ) {
    // do something with c
  }
}

Your echo | essentially pipes EOF to the program. You can type Ctrl-d to tell that input ends.

3. A search path is usually an ordered list. You can verify that:
mkdir foo bar
`gcc -print-prog-name=cc1` -v -Ifoo -Ibar

If you have header with same name (but different content) in both directories and compile something (that has that include) with -Ifoo -Ibar you will see which path has priority.
Those "apostrophies" are called "back quotes". keskiverto's explanation pretty much covers it.
Registered users can post here. Sign in or register to post.