I’m attempting to build Zig from source, but I’m hitting a snag with CMake. I’ve built from source on a different computer before (my MacBook), so I’m vaguely familiar with the process, but I’m getting tripped up with LLVM. For reference, I’m using Linux Mint 21 (based on Ubuntu 22.04).
I’ve followed along with the docs on GitHub. I followed the instructions to install LLVM 18 and used the docs from LLVM’s site to install all the dependencies (first I used the Automatic installation script found at the top of the page; then I followed up by installing all key pages found later in the page).
After all these steps, I’m still met with the following error:
$ mkdir build
$ cd build
$ cmake ..
-- Configuring zig version 0.13.0-dev.365+332fbb4b0
-- Could NOT find clang (missing: CLANG_LIBRARIES) (Required is at least version "18")
-- Could NOT find lld (missing: LLD_LIBRARIES LLD_INCLUDE_DIRS) (Required is at least version "18")
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/home/christian/Coding/Zig/zig/LLD_INCLUDE_DIRS
used as include directory in directory /home/christian/Coding/Zig/zig
CLANG_LIBRARIES (ADVANCED)
linked by target "zigcpp" in directory /home/christian/Coding/Zig/zig
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
-- Could NOT find clang (missing: CLANG_LIBRARIES) (Required is at least version "18")
-- Could NOT find lld (missing: LLD_LIBRARIES LLD_INCLUDE_DIRS) (Required is at least version "18")
I already ran the Automatic installation script and have clang-18 and ld.lld-18 installed (I even created symbolic-links for clang and ld.lld respectively), but I still receive the same error as above.
I myself tested the zig compilation with containers. Here’s its content if it can help to find what packages are missing.
ContainerFile
FROM ubuntu:24.04
ENV UID=1000
ENV GID=1000
ENV USER=ubuntu
#Update the image to the latest packages
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && apt upgrade -y
RUN apt install -y build-essential cmake clang-18 libclang-18-dev libclang-cpp18-dev llvm-18 llvm-18-dev lld-18 liblld-18-dev libpolly-18-dev libllvm18
RUN apt clean && rm -rf -- /var/lib/apt/lists/*
VOLUME /zig
WORKDIR /zig
CMD [ "/bin/bash" ]
I then used podman to test the build (work with docker too)
##############################################
# Command to use the container
##############################################
cd zig/
# Create the image
touch ContainerFile # <== Copy the content above here.
podman build -f ContainerFile --tag=zig/build .
# Run the image
podman run --rm -it -v ./:/zig --name=zig zig/build
##############################################
# Command for build
##############################################
mkdir build && cd build
# Release build example
cmake -DCMAKE_BUILD_TYPE=Release ../
make -j$(nproc) install
You find it by understanding the relationship between the upstream project, the dependency project, and the Linux distribution project.
Upstream is Zig, which depends on LLVM. Ubuntu is the Linux distribution.
LLVM has its own build system and configuration options. You’re choosing to use LLVM provided by Ubuntu, which has made configuration choices on your behalf. Zig expects to find dependency libraries in a standardized manner.
Knowing all this, it’s a matter of guessing that there is an Ubuntu package which provides the required files in the standard location. It’s not really something that belongs on Zig or LLVM’s documentation or issue tracker. If you built LLVM from source yourself, for example, this would not be a problem.
In summary, it’s an issue that you opt into by using Ubuntu to provide LLVM.