Skip to content

Homebrew Clang does not have correct search path for system include directory on MacOS Catalina #45061

@ssbanerje

Description

@ssbanerje

Homebrew Clang does not search the correct include directories in MacOS Catalina.

What you were trying to do (and why)

If I try to compile the following C file after installing LLVM+Clang from homebrew

#include <stdio.h>

int main() {
    printf("hi");
}

What happened

I get the error

» which clang                                                                                                                                                                                             1 ↵
/usr/local/opt/llvm/bin/clang
» clang test.c
In file included from test.c:1:
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
#include <stdio.h>
              ^~~~~~~~~
1 error generated.

What you expected to happen

The program to compile correctly.

However, if I alias clang to the system clang, everything works!

» alias clang=/usr/bin/clang                                                                                                                                                                              1 ↵
» clang test.c
» ./a.out
hi%

By default the Homebrew clang has the following search paths

» echo | clang -E -Wp,-v -
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/Cellar/llvm/9.0.0/lib/clang/9.0.0/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 352 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

The system clang looks in different folders

» alias clang=/usr/bin/clang
» echo | clang -E -Wp,-v -
clang -cc1 version 11.0.0 (clang-1100.0.33.8) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 362 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

I think the problem is that until recently /usr/include would have the header files that the compiler requires, however, that directory does not exist anymore (since Catalina update).

I can currently work around this by explicitly setting CPATH. But I think this is a bug, not sure if it is a homebrew problem or upstream in LLVM.

Step-by-step reproduction instructions (by running brew commands)

brew install llvm
export PATH="/usr/local/opt/llvm/bin:$PATH"
clang test.c

My homebrew is updated to the latest version and doctor does not report any problems.

» brew -v                                                                                                                                                                                                 1 ↵
Homebrew 2.1.13
Homebrew/homebrew-core (git revision 4d523; last commit 2019-10-09)
Homebrew/homebrew-cask (git revision c4f9d3; last commit 2019-10-09)

» brew doctor
Your system is ready to brew.

» brew config
HOMEBREW_VERSION: 2.1.13
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: aa043c1d678afd26f50156a83417c296cb9d5a4b
Last commit: 24 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 4d5233f01f792cb83661ccc1a6abfb139c168951
Core tap last commit: 4 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_VISUAL: nvim
CPU: quad-core 64-bit broadwell
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1100
Git: 2.23.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 12.0.1, 1.8.0_131, 1.8.0_40
macOS: 10.15-x86_64
CLT: 11.0.0.0.1.1567737322
Xcode: 11.1
CLT headers: 11.0.0.0.1.1567737322
XQuartz: 2.7.11 => /opt/X11

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedPR was locked due to age

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions