llvm学习(十):修复 macOS Catalina 缺失 /usr/include 导致的clang无法使用

今天升了macOS10.15,发现自己编译的llvm和clang坏掉了,重新编译也没用,而自带的/usr/clang是没有问题的,发现是 /usr/include 缺失。

一、背景

Command Line Tools 10.13系列,是拥有/usr/include目录的,之前一直在用。但是在macOS 10.15上无法安装它,就很气。

Command Line Tools 10.14系列,砍掉了32位的编译环境,也砍掉了/usr/include。

macOS 10.15砍掉了 32 位的运行环境,将 / 挂载为 read-only。

而自己编译的llvm+clang是不会主动去寻找 MacOSXSDK的头文件的,就出现了找不到头文件的情况。

二、修复过程(中英双语,中文更简单、英文更详细)

人肉diff 一下曾经的

和 现在的

发现后者比前者多出少量的.h 文件,但缺少 c++目录。

而现在的 c++目录在

因此思路很简单

1、恢复 c++

2、重启到 recovery 关掉 SIP

3、重启到操作系统

4、重启到 recovery 开启 SIP

5、效果

这时候/usr/include 下面就有 c 和 cpp 常用的头文件了,自己编译的 llvm 和 clang 也就可以正常使用了

三、Repair it

Since Command-Line-Tools >= 10.14, there is no /usr/include path.

And after macOS Catalina, ‘/’ partition is read-only. So I finally fix it by myself.

I diff the /usr/include for 10.13 and /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include for 10.15. The only difference is that:

– Most of them are the same.

– 10.15 has more header files, maybe some new feature.

– 10.13 has c++ directory, which is /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++ in macOS 10.15.

So do the following things:

  1. add c++ headers

sudo ln -s /Library/Developer/CommandLineTools/usr/include/c++ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++

  1. reboot to recovery and disable SIP
  2. reboot to desktop,

sudo mount -uw /

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include /usr/include

  1. reboot to recovery and enable SIP.
  2. result:

四、相关链接

https://github.com/Homebrew/homebrew-core/issues/45061

https://discourse.brew.sh/t/clang-can-no-longer-find-usr-include-header-files-fatal-error-stdlib-h-file-not-found/4523/7


=============================================================
随着访客的增多,LeadroyaL在本站流量的开支越来越多了,曾经1元能用1个月,现在1元只能用3天。如果觉得本文帮到了你,希望能够为服务器的流量稍微打赏一点,谢谢!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*

code