Ch1.4: Clang
What Is Clang?
Clang is a modern C and C++ compiler front‑end from the LLVM project. It is designed to be fast,
modular, and highly portable. Unlike GCC, Clang allows you to freely specify
--target at compile time, which makes cross‑compilation extremely easy.
Clang is widely used in industry because of its:
- excellent diagnostics and error messages
- fast compilation speed
- clean architecture and modular design
- support for many platforms (Windows, Linux, macOS, Android, WebAssembly, etc.)
- compatibility with both GNU and MSVC toolchains
In this tutorial, Clang is our primary compiler because it can generate binaries for nearly every
platform, including Windows MSVC binaries, Linux binaries, macOS binaries, Android binaries, and
WebAssembly binaries. Clang also integrates cleanly with the windows-msvc-sysroot
provided in this tutorial, allowing you to build MSVC‑compatible Windows executables on any OS.
Install Git
Before downloading the toolchain scripts, ensure that Git is installed on your system.
- Linux: install via your package manager (e.g.,
sudo apt install git) - macOS: install via Homebrew (
brew install git) or Xcode Command Line Tools - Windows: install from git-scm.com
- Android (Termux): install via
pkg install git
Clone the Toolchain Build Scripts
The Clang toolchains used in this tutorial are built using the author's automated build scripts. Clone the repository using one of the following commands:
git clone https://github.com/trcrsired/toolchainbuildscripts.git-
git@github.com:trcrsired/toolchainbuildscripts.git
(Note: SSH cloning may be blocked by the Great Firewall in China.)
After cloning, enter the repository directory to access the installation scripts.
Download Native Toolchains
To download the toolchains for your current host system, run the appropriate script:
- Linux / macOS / BSD / Android:
./installs/host_download.sh -
Windows PowerShell:
./installs/windows/host_download.ps1
You may need to run PowerShell as Administrator or temporarily bypass execution restrictions:Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
You can also enable optional components by setting environment variables:
CLONE_WINDOWS_MSVC_SYSROOT=yes— clones the Windows MSVC sysroot for building Windows binariesCLONE_FAST_IO=yes— automatically clones the fast_io library
Download All Toolchains
If you want every supported toolchain (not just the native one), use the all_download scripts:
- POSIX systems:
./installs/all_download.sh - Windows:
./installs/windows/all_download.ps1
These scripts download all available toolchains.
In this case, you do not need to run host_download.
Troubleshooting
If you encounter issues during installation:
- Verify your network connection and proxy settings
- Ensure Git and PowerShell permissions are configured correctly
- Check that your shell has permission to execute the scripts
- Ask AI assistants such as Microsoft Copilot or ChatGPT for help diagnosing errors
Once the toolchains are downloaded, you are ready to begin compiling with Clang.
Manual Installation (If Auto‑Install Fails)
If the automated installation scripts fail due to network issues, proxy configuration, or platform restrictions, you can install the toolchains manually by downloading the prebuilt releases directly.
- llvm-releases — fast_io author's latest Clang/LLVM builds
- wavm-releases — includes WebAssembly Memory Tagging support (ACM CCSW 2025 publication: link)
- windows-msvc-sysroot — required for building Windows binaries with Clang
-
fast_io Library
— clone with
-b nextto use the development branch
After downloading the archives or cloning the repositories, extract them and configure your environment variables manually:
- PATH: add the compiler’s
bindirectory - LD_LIBRARY_PATH: (Linux/BSD/Android) add the toolchain’s
libdirectory - DYLD_LIBRARY_PATH: (macOS) add the toolchain’s
libdirectory - WINEPATH: if using Wine to run Windows binaries
If you are unsure how to replicate the automated steps manually, you can open the
host_download.sh or host_download.ps1 scripts and feed them to an AI assistant
(such as Microsoft Copilot or ChatGPT). It will explain exactly what each step does so you can reproduce it by hand.