diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index bbfc418214396..8dd6f95c8d90a 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -37,6 +37,17 @@ def homebrew_extra_paths paths end + def homebrew_extra_isystem_paths + paths = [] + # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. + if deps.any? { |d| d.name == "glibc@2.13" } + gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp + gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp + paths << gcc_include_dir << gcc_include_fixed_dir + end + paths + end + def determine_rpath_paths(formula) PATH.new( *formula&.lib, diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 7d68f9fc5fe3c..7d1c5eb6a1cc7 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -292,6 +292,8 @@ class Cmd args.concat(optflags) unless runtime_cpu_detection? args.concat(archflags) args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0) + # Add -nostdinc when building against glibc@2.13 to avoid mixing system and brewed glibc headers. + args << "-nostdinc" if @deps.include?("glibc@2.13") args end @@ -326,6 +328,9 @@ class Cmd end args += rpath_flags("#{wl}-rpath=", rpath_paths) args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path + # Use -rpath-link to make sure linker uses glibc@2.13 rather than the system glibc for indirect + # dependencies because -L will only handle direct dependencies. + args << "#{wl}-rpath-link=#{@opt}/glibc@2.13/lib" if @deps.include?("glibc@2.13") args end