首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在macOS上自制的LLVM“致命错误:'stdio.h‘文件未找到”

在macOS上自制的LLVM“致命错误:'stdio.h‘文件未找到”
EN

Stack Overflow用户
提问于 2019-09-01 14:24:55
回答 2查看 4.2K关注 0票数 2
  1. 安装LLVM brew install llvm

  1. 编辑.zshrc
代码语言:javascript
复制
...
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
代码语言:javascript
复制
#include <stdio.h>
int main()
{
    printf("Hello, World!");
    return 0;
}
  1. 现在,当我运行clang -v hello.c时,我得到:
代码语言:javascript
复制
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是符号链接

,有什么问题吗?

EN

回答 2

Stack Overflow用户

发布于 2021-06-29 18:34:04

如果使用外部LLVM安装,请将它们添加到~/.bash_profile中。

代码语言:javascript
复制
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

票数 4
EN

Stack Overflow用户

发布于 2019-09-02 08:45:06

因为ignoring nonexistent directory "/usr/include"

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57746792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档