user11679606
user11679606

Reputation:

Homebrew's LLVM "fatal error: 'stdio.h' file not found" on macOS

  1. Install LLVM brew install llvm


  2. Edit .zshrc

...
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
...

  1. Create hello.c
#include <stdio.h>
int main()
{
    printf("Hello, World!");
    return 0;
}

  1. Now, when i run clang -v hello.c, I get:
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
 "/usr/local/Cellar/llvm/8.0.1/bin/clang-8" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 450.3 -v -resource-dir /usr/local/Cellar/llvm/8.0.1/lib/clang/8.0.1 -fdebug-compilation-dir /Users/jdriwer/Projects -ferror-limit 19 -fmessage-length 212 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qg/47c_70qn4wd9tlp18280f7k00000gn/T/hello-4a50cb.o -x c hello.c
clang -cc1 version 8.0.1 based upon LLVM 8.0.1 default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/Cellar/llvm/8.0.1/lib/clang/8.0.1/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

PS. llvm's stdio.h location: /usr/local/Cellar/llvm/8.0.1/include/c++/v1/stdio.h and /usr/local/opt/llvm ⇒ ../Cellar/llvm/8.0.1 is symbolic link


What's the trouble?

Upvotes: 3

Views: 6297

Answers (2)

Amin Ya
Amin Ya

Reputation: 1938

If using an external LLVM installation, add these to your ~/.bash_profile

LLVM_PATH="/usr/local/opt/llvm/" # or any other path
LLVM_VERSION="11.0.0"
export PATH="$LLVM_PATH:$PATH"
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LD_LIBRARY_PATH="$LLVM_PATH/lib/:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="$LLVM_PATH/lib/:$DYLD_LIBRARY_PATH"
export CPATH="$LLVM_PATH/lib/clang/$LLVM_VERSION/include/"
export LDFLAGS="-L$LLVM_PATH/lib"
export CPPFLAGS="-I$LLVM_PATH/include"
export CC="$LLVM_PATH/bin/clang"
export CXX="$LLVM_PATH/bin/clang++"

(adjust the clang version and the external llvm installation path.)

Then run source ~/.bash_profile

Upvotes: 6

user11679606
user11679606

Reputation:

Because ignoring nonexistent directory "/usr/include"

You should install macOS SDK headers from /Library/Developer/CommandLineTools/Packages/

Upvotes: 2

Related Questions