在 macOS 上安装 clang-format
Mar 06, 2025
clang-format 命令并没有包含在 Xcode 中,需要手动安装。 $ sudo port install clang-19 clang_select llvm-19 llvm_select 安装后把 clang-19 设置为默认版本: $ sudo port select --set llvm mp-llvm-19 $ sudo port select --set clang mp-clang-19 现在就可以使用 clang-format 命令了。 格式化相关的选项可以参考: https://clang.llvm.org/docs/ClangFormatStyleOptions.html …
在 Alpine Linux 上使用 Clang
Mar 02, 2025
Alpine Linux 的 libc 使用的是 musl ,Clang 是作为前端编译器,实际链接的时候是使用 musl 的库。 安装 Clang 和 lld: $ apk add clang lld 编译 C 源码: $ clang -fuse-ld=lld main.c $ ldd a.out /lib/ld-musl-aarch64.so.1 (0xfff561cb0000) libc.musl-aarch64.so.1 => /lib/ld-musl-aarch64.so.1 (0xfff561cb0000) 可以看到依赖很干净,不像 glibc 那样。 …
在 Fedora 上使用 musl Clang
Mar 02, 2025
测试的系统环境是 Fedora 41 musl 是轻量级的 libc 实现,Docker 官方的容器使用的 Alpine 系统就是把 musl 作为它的默认 libc 库。 $ sudo dnf install musl-clang lld musl 的头文件和库文件的路径是 /usr/{arch}-linux-musl,使用命令 musl-clang 可以像 clang 一样直接编译 C 源码,它已经把 musl 需要的环境都包装好了: …
在 Fedora 上安装 Clang 开发环境
Mar 01, 2025
测试环境使用的系统是 Fedora 41: https://fedoraproject.org/workstation/download Clang 是编译器前端,后端还是默认依赖 GCC 的运行库实现,如果想要使用全套 Clang 工具链,需要额外安装 libcxx, llvm-libunwind-static,llvm-libunwind-devel 运行库和 lld 链接器: …
Clang 编译 Apple 全平台的 triple 和 sysroot 配置
May 04, 2024
Apple 平台上采用的是 Fat 模式的编译方式,就是编译的目标可以同时包含多种不同的架构,比如 macOS 上就可以同时包含 3 种架构: i386, x86_64 和 arm64。 Apple 平台的另一个编译特点就是可以指定最低系统版本,比如在编译时可以指定 macOS 最低的系统要求是 10.15。 …
Linux 中使用 Clang 的 Block 扩展
Apr 29, 2023
Block 是 Objtive-C 语言的一个特性,Clang 把这个特性作为扩展带到了 C/C++ 中: https://clang.llvm.org/docs/BlockLanguageSpec.html 先从 LLVM 的源安装最新版本的 Clang: sudo apt install lsb-release wget software-properties-common gnupg2 安装 LLVM 源: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" 同时也安装了最新版本的 Clang。 …
bitcode 被废弃了
Sep 24, 2022
在 Xcode 14 的发布日志中: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes Apple Clang Compiler Deprecations Starting with Xcode 14, bitcode is no longer required for watchOS and tvOS applications, and the App Store no longer accepts bitcode submissions from Xcode 14. Xcode no longer builds bitcode by default and generates a warning message if a project explicitly enables bitcode: “Building with bitcode is deprecated. Please update your project and/or target settings to disable bitcode.” The capability to build with bitcode will be removed in a future Xcode release. IPAs that contain bitcode will have the bitcode stripped before being submitted to the App Store. Debug symbols for past bitcode submissions remain available for download. (86118779) …
Visual Studio 2022 中使用 Clang
May 15, 2022
本文适用 Visual Studio 2017 以及更高版本 下载 LLVM for Windows 当前最新的 LLVM 版本是 14.0.3,在以下链接可以下载官方编译好的版本: https://github.com/llvm/llvm-project/releases x86: LLVM-14.0.3-win32.exe x86_64: LLVM-14.0.3-win64.exe arm64: LLVM-14.0.3-woa64.zip 我下载的是 LLVM-14.0.3-win64.exe,安装在目录 C:\Program Files\LLVM-14.0.3 …
clang 跨平台编译 iOS/macOS arm64/x86_64
May 19, 2021
Target 不同的目标平台对应不同的 -target $triple 参数: iOS 平台: armv7:-target arm64-apple-darwin arm64:-target armv7-apple-darwin macOS 平台: i386:-target i386-apple-macos x86_64:-target x86_64-apple-macos …
使用 -l 链接时,如何确定链接动态库还是静态库
Apr 25, 2021
比如:-lssl 是链接到 libssl.a 还是 libssl.so? 由编译参数决定: -Wl,-static,静态链接。 -Wl,-dynamic,动态链接。 如果动态库和静态库混乱链接,加上 -search_paths_first。 …