Why could GCC prefer to use stdio.h file from later in the include path?

93 Views Asked by At

While compiling a Ruby gem's native extension, I get this error according to logs:

LD_LIBRARY_PATH=.:/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/lib "gcc-12 -M -o conftest -I/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0/x86_64-linux -I/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0/ruby/backward -I/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0 -I. -I/opt/local/include -I/usr/local/include -I/opt/homebrew/include -I/usr/include -I/home/linuxbrew/.linuxbrew/opt/libyaml/include -I/home/linuxbrew/.linuxbrew/opt/openssl@3/include -I/home/linuxbrew/.linuxbrew/opt/readline/include   -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC conftest.c  -L. -L/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/lib -L/opt/local/lib -Wl,-rpath,/opt/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/opt/homebrew/lib -Wl,-rpath,/opt/homebrew/lib -L/usr/lib -Wl,-rpath,/usr/lib -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L/home/linuxbrew/.linuxbrew/opt/readline/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/readline/lib -L. -fstack-protector-strong -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L/home/linuxbrew/.linuxbrew/opt/readline/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/readline/lib -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed     -Wl,-rpath,/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/lib -L/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/lib -lruby  -lm  -lc"
In file included from /home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0/ruby/defines.h:16,
                 from /home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0/ruby/ruby.h:25,
                 from /home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.1.3_1/include/ruby-3.1.0/ruby.h:38,
                 from conftest.c:1:
/usr/include/stdio.h:781:10: fatal error: bits/sys_errlist.h: No such file or directory
  781 | #include <bits/sys_errlist.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

The problem is that in the -I arguments you can see -I/opt/homebrew/include -I/usr/include, and the first of these directories has /opt/homebrew/include/stdio.h which doesn't contain #include <bits/sys_errlist.h>. As far as I understand https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html, it should be used instead of /usr/include/stdio.h. What am I missing and how can I fix the problem?

Versions:

  • WSL 1.0.3.0
  • Ubuntu 20.04
  • Homebrew GCC 12.2.0
  • Homebrew Ruby 3.1.3
1

There are 1 best solutions below

0
Alexey Romanov On

The awful (but working for me) workaround:

  1. Rename /usr/include;
  2. Compile;
  3. Rename it back.