Segmentation fault when building from source

Hello :slight_smile:

I’m trying to build Zig from source on Debian 12 Bookworm. I did mkdir build && cd build, cmake .. and got everything working, but when I do make install, I get the error

[ 36%] Built target zigcpp
[ 47%] Built target zig-wasm2c
[ 68%] Built target zig1
[ 94%] Built target zig2
[100%] Building stage3
Segmentation fault
make[2]: *** [CMakeFiles/stage3.dir/build.make:73: stage3/bin/zig] Error 139
make[1]: *** [CMakeFiles/Makefile2:196: CMakeFiles/stage3.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

does anyone know what could be causing this and/or how I can fix it?

This still happens on 6/30/2025, when attempting 0.14.x on Debian Sid.

Hello @steveo314 Welcome to ziggit :slight_smile:
Note that 0.14.x requires llvm 19.
See: Building Zig from source for dummies? - #37 by dimdin for a way to build zig 0.14.x using the llvm apt repository.
If you want to also build llvm from sources see: Building Zig from source for dummies? - #6 by matklad but change llvm 18 to llvm 19.

1 Like

ill double check to see if i still get the error but Sid has had llvm 19 for a bit. Debian 12 has llvm 14. Trixie will release with 19. I may have been trying to compile zig 0.15. which i’m guessing would need 20 or 21.

update:

debian → sid/unstable branch
cmake → 3.31.6
llvm → 19.0
zig branch → 0.14.x
gcc → 15.1.0 (from debian experimental branch)

same segmentation fault as OP when running make install

update2:

when trying to compile this way, still get the seg fault

git clone <...>
cd zig
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
make   ## seg fault occurence
make install

update3:

sudo apt update
sudo apt install libclang-19-dev liblld-19-dev llvm-19-dev 
git clone https://github.com/ziglang/zig
cd zig
mkdir build
cd build

###  seg  fault
cmake .. -DCMAKE_PREFIX_PATH=/usr/lib/llvm-19 -DCMAKE_BUILD_TYPE=Release -DZIG_NO_LIB=ON -GNinja


ninja install
stage3/bin/zig version
➜  build git:(0.14.x) ninja install
[19/20] Building stage3
FAILED: stage3/bin/zig /home/steve/Downloads/zig/build/stage3/bin/zig
cd /home/steve/Downloads/zig && /home/steve/Downloads/zig/build/zig2 build --prefix /home/steve/Downloads/zig/build/stage3 --zig-lib-dir /home/steve/Downloads/zig/lib -Dversion-string=0.14.2-dev.1+6d1f0eca7 -Dtarget=native -Dcpu=native -Denable-llvm -Dconfig_h=/home/steve/Downloads/zig/build/config.h -Dno-langref -Doptimize=ReleaseFast -Dstrip -Dno-lib
Segmentation fault
ninja: build stopped: subcommand failed.