1

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

LD_LIBRARY_PATH=.:/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/lib "gcc-12 -M -o conftest -I/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/include/ruby-3.1.0/x86_64-linux -I/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/include/ruby-3.1.0/ruby/backward -I/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/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/ruby@3.1/3.1.3_1/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/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/ruby@3.1/3.1.3_1/lib -L/home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/lib -lruby  -lm  -lc"
In file included from /home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/include/ruby-3.1.0/ruby/defines.h:16,
                 from /home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/3.1.3_1/include/ruby-3.1.0/ruby/ruby.h:25,
                 from /home/linuxbrew/.linuxbrew/Cellar/ruby@3.1/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
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • 1
    According to the standard, you are not allowed to override a standard header. "If a file with the same name as [a standard header] is placed in any of the standard places that are searched for included source files, the behavior is undefined." The compiler is allowed to recognize standard headers and (for example) load pre-tokenized versions instead of reading the textual version. However, it appears that the gcc documentation explicitly permits it. The documentation might be out of date, since header file inclusion was changed significantly in C++20 due to modules. – Raymond Chen Feb 13 '23 at 14:32
  • Actually, does an `-I` argument count as one "of the standard places that are searched for included source files"? – Alexey Romanov Feb 13 '23 at 15:13
  • The phrasing appears to be a wording defect. The phrase "standard place" does not appear anywhere else. The specification for `#include` calls them "implementation-defined places." – Raymond Chen Feb 13 '23 at 21:50

1 Answers1

0

The awful (but working for me) workaround:

  1. Rename /usr/include;
  2. Compile;
  3. Rename it back.
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487