【问题标题】:Homebrew's LLVM "fatal error: 'stdio.h' file not found" on macOSHomebrew 的 LLVM 在 macOS 上出现“致命错误:'stdio.h' 文件未找到”
【发布时间】:2020-01-04 21:24:07
【问题描述】:
  1. 安装 LLVM brew install llvm


  2. 编辑.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. 创建hello.c
#include <stdio.h>
int main()
{
    printf("Hello, World!");
    return 0;
}

  1. 现在,当我运行 clang -v hello.c 时,我得到:
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 的stdio.h 位置:/usr/local/Cellar/llvm/8.0.1/include/c++/v1/stdio.h /usr/local/opt/llvm ⇒ ../Cellar/llvm/8.0.1 是符号链接


有什么问题?

【问题讨论】:

  • 你说stdio.h的位置是/usr/local/Cellar/llvm/8.0.1/include/c++/v1/stdio.h而你是export CPPFLAGS="-I/usr/local/opt/llvm/include"?对我来说没有多大意义。
  • /usr/local/opt/llvm ⇒ ../Cellar/llvm/8.0.1 是符号链接
  • 什么是使用 $LDFLAGS$CPPFLAGS。这些环境变量听起来像标准的Makefile 变量,但make 似乎并没有在这里涉及。也将它们设置在您的个人资料中,而不是 Makefile,例如也没有多大意义。
  • @trojanfoe 这些是来自brew info llvm的推荐
  • @trojanfoe 忽略,因为目录不存在。 macOS SDK headers 安装他的 stdio.h(/usr/local/Cellar/llvm/8.0.1/include/c++/v1/stdio.h 为空并使用 #include_next)。我在重新安装 macOS 时反复遇到这个问题,但总是忘记。 Xcode command line 已安装,因为我使用自制软件。我的回答对我有用。

标签: c macos clang llvm llvm-clang


【解决方案1】:

因为ignoring nonexistent directory "/usr/include"

你应该从/Library/Developer/CommandLineTools/Packages/安装macOS SDK headers

【讨论】:

  • 我在 Catalina 上找不到 /Library/Developer/CommandLineTools/Packages/ 这样的目录
  • 是的,我在 Catalina 上遇到了同样的问题。有一个`/Library/Developer/CommandLineTools/Library SDKs`代替。
【解决方案2】:

如果使用外部 LLVM 安装,请将这些添加到您的 ~/.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++"

(调整clang版本和外部llvm安装路径。)

然后运行source ~/.bash_profile

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 2021-06-13
    • 2013-05-15
    • 1970-01-01
    • 2020-10-12
    • 2020-03-22
    • 1970-01-01
    • 2022-07-18
    • 2022-08-02
    相关资源
    最近更新 更多