Building C3 from source
Want To Download Pre-Built C3 Binaries?
Download C3, available on Mac, Windows and Linux.
Building C3 from source is straightforward as the CMake configuration can automatically download the pre-compiled LLVM binaries. You will need git, CMake, and a C compiler (such as Clang, GCC, or MSVC) installed on your system.
Faster Builds
For faster compilation, you can compile in parallel by appending the -j flag (e.g., cmake --build build -j). Alternatively, if you have Ninja installed, you can generate Ninja build files by adding -G Ninja to the configuration step (e.g., cmake -B build -S . -G Ninja ...).
Compiling on Linux¶
- Install the required build dependencies using your distribution's package manager:
- Ubuntu / Debian:
sudo apt-get install cmake git clang libcurl4-openssl-dev - Fedora:
sudo dnf install cmake clang git libcurl-devel - Arch Linux:
sudo pacman -S curl clang cmake git - Void Linux:
sudo xbps-install git cmake clang libcurl-devel
- Ubuntu / Debian:
- Clone the compiler repository:
- Configure and build the compiler:
- Run the compiled compiler to verify:
Compiling on macOS¶
First, ensure you have the Xcode Command Line Tools installed by running:
Using Homebrew¶
- Install CMake:
- Clone the compiler repository:
- Configure and build the compiler:
Building via Homebrew Formula
You can also compile the latest development version (master branch) directly using Homebrew by running brew install c3c --HEAD. To upgrade it later, use brew reinstall c3c. If you need to customize the compilation settings, you can do so by editing the formula script (using brew edit c3c).
Using MacPorts¶
If you are using MacPorts, you can either let CMake fetch LLVM automatically or use the MacPorts LLVM package.
To build using automatic LLVM fetching: 1. Install CMake: sudo port install cmake 2. Clone the repository and build:
git clone https://github.com/c3lang/c3c.git
cd c3c
cmake -B build -S . -DC3_FETCH_LLVM=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build
To build using the LLVM installed via MacPorts: 1. Install the required ports: sudo port install cmake llvm-17 clang-17 2. Clone the repository: git clone https://github.com/c3lang/c3c.git and enter the directory. 3. Configure pointing to the MacPorts LLVM directory and build:
export LLVM_DIR=/opt/local/libexec/llvm-17/lib/cmake/llvm
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build
Compiling on Windows¶
- Install Visual Studio 2022 (VS17) with the "Desktop development with C++" workload, or install the standalone Build Tools.
- Install Git and CMake.
- Clone the compiler repository:
- Configure and build the compiler: The resulting executable will be located in
cmake --preset windows-vs-2022-release -D C3_FETCH_LLVM=ON cmake --build --preset windows-vs-2022-releasebuild\Release\c3c.exe.
For a debug build, configure and build with the debug preset instead:
cmake --preset windows-vs-2022-debug -D C3_FETCH_LLVM=ON
cmake --build --preset windows-vs-2022-debug
Docker and NixOS¶
A script is provided to build C3 inside an Ubuntu Docker container:
For NixOS users, enter the development shell and configure CMake with the required flags: