# Help with building zig from source (cmake on macOS, with homebrew; trouble linking zstd)

**URL:** <https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381>\
**Category:** Help\
**Tags:** zig-master\
**Created:** [October 15, 2024, 4:18am UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381 "2024-10-15T04:18:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark-rushakoff](https://ziggit.dev/user_avatar/ziggit.dev/mark-rushakoff/32/3551_2.png) [@mark-rushakoff](https://ziggit.dev/u/mark-rushakoff)\
**Post date:** [October 15, 2024, 4:18am UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/1 "2024-10-15T04:18:00Z")

</div>

I’ve been trying to build zig from source, and I’m struggling with cmake configuration on macOS. I would prefer to build completely from source locally, without downloading a prebuilt zig binary for bootstrapping. I am a bit out of my element with cmake, so I was hoping someone here would have a quick answer that would save me hours of time trying to debug this.

First I was trying to only follow the Option A, For macOS + Homebrew section of the wiki.

I was getting issues with linking zstd. I tried both the wiki’s recommended `-DCMAKE_PREFIX_PATH="...;$(brew --prefix zstd)"`, and I tried `...;$(brew --prefix zstd)/lib"` but neither solved the issue.

I have zstandard installed through homebrew; here’s the content of the /lib variant:

```zig
$ ls "$(brew --prefix zstd)/lib"
cmake libzstd.1.5.6.dylib libzstd.1.dylib libzstd.a libzstd.dylib pkgconfig

```

After getting nowhere with that, I found this post from Andrew:

> [@Building Zig from source for dummies?](https://ziggit.dev/t/building-zig-from-source-for-dummies/4729/5):
>
> Anyway, I strongly recommend this workflow for you:
> 
> 1. [How to build LLVM, libclang, and liblld from source · ziglang/zig Wiki · GitHub](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix)
> 2. [Contributing · ziglang/zig Wiki · GitHub](https://github.com/ziglang/zig/wiki/Contributing#editing-source-code)

So I did step 1, but then the Contributing page on the wiki only links back to the building zig from source page (and then it suggests some other flags to refine the workflow, none of which look like they affect how to link against zstd.

Then I slightly adjusted the command in the building from source wiki page:

```shell
$ cmake .. -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="$HOME/local/llvm19-assert;$(brew --prefix lld);$(brew --prefix zstd)/lib;$(brew --prefix zstd)" -DCMAKE_BUILD_TYPE=Release -DZIG_NO_LIB=on
-- Configuring zig version 0.14.0-dev.1911+3bf89f55c
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/hh/src/zig/build

```

I am pointing at my local source build of llvm, and I am specifying both zstd and zstd/lib in vain hopes that one sticks.

Finally, while still in the same directory, `make install/local` fails (trying to keep the build local so I can continue to run a stable zig from my $PATH but have a build from master available elsewhere).

```shell
$ make install/local
[36%] Built target zigcpp
[47%] Built target zig-wasm2c
[68%] Built target zig1
[73%] Linking CXX executable zig2
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [zig2] Error 1
make[1]: *** [CMakeFiles/zig2.dir/all] Error 2
make: *** [all] Error 2

```

I have the output from verbose=on here:

> **make install/local VERBOSE=on**
>
> ```shell
> $ make install/local VERBOSE=on
> /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -S/Users/hh/src/zig -B/Users/hh/src/zig/build --check-build-system CMakeFiles/Makefile.cmake 0
> /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_progress_start /Users/hh/src/zig/build/CMakeFiles /Users/hh/src/zig/build//CMakeFiles/progress.marks
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zigcpp.dir/build.make CMakeFiles/zigcpp.dir/depend
> cd /Users/hh/src/zig/build && /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/hh/src/zig /Users/hh/src/zig /Users/hh/src/zig/build /Users/hh/src/zig/build /Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/DependInfo.cmake "--color="
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_clang.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_clang_cc1_main.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_clang_cc1as_main.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_clang_driver.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_llvm-ar.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zigcpp.dir/src/zig_llvm.cpp.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zigcpp.dir/compiler_depend.internal".
> Consolidate compiler generated dependencies of target zigcpp
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zigcpp.dir/build.make CMakeFiles/zigcpp.dir/build
> make[2]: Nothing to be done for `CMakeFiles/zigcpp.dir/build'.
> [36%] Built target zigcpp
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig-wasm2c.dir/build.make CMakeFiles/zig-wasm2c.dir/depend
> cd /Users/hh/src/zig/build && /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/hh/src/zig /Users/hh/src/zig /Users/hh/src/zig/build /Users/hh/src/zig/build /Users/hh/src/zig/build/CMakeFiles/zig-wasm2c.dir/DependInfo.cmake "--color="
> Dependencies file "CMakeFiles/zig-wasm2c.dir/stage1/wasm2c.c.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zig-wasm2c.dir/compiler_depend.internal".
> Consolidate compiler generated dependencies of target zig-wasm2c
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig-wasm2c.dir/build.make CMakeFiles/zig-wasm2c.dir/build
> make[2]: Nothing to be done for `CMakeFiles/zig-wasm2c.dir/build'.
> [47%] Built target zig-wasm2c
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig1.dir/build.make CMakeFiles/zig1.dir/depend
> cd /Users/hh/src/zig/build && /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/hh/src/zig /Users/hh/src/zig /Users/hh/src/zig/build /Users/hh/src/zig/build /Users/hh/src/zig/build/CMakeFiles/zig1.dir/DependInfo.cmake "--color="
> Dependencies file "CMakeFiles/zig1.dir/stage1/wasi.c.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zig1.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zig1.dir/zig1.c.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zig1.dir/compiler_depend.internal".
> Consolidate compiler generated dependencies of target zig1
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig1.dir/build.make CMakeFiles/zig1.dir/build
> make[2]: Nothing to be done for `CMakeFiles/zig1.dir/build'.
> [68%] Built target zig1
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig2.dir/build.make CMakeFiles/zig2.dir/depend
> cd /Users/hh/src/zig/build && /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/hh/src/zig /Users/hh/src/zig /Users/hh/src/zig/build /Users/hh/src/zig/build /Users/hh/src/zig/build/CMakeFiles/zig2.dir/DependInfo.cmake "--color="
> Dependencies file "CMakeFiles/zig2.dir/compiler_rt.c.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zig2.dir/compiler_depend.internal".
> Dependencies file "CMakeFiles/zig2.dir/zig2.c.o.d" is newer than depends file "/Users/hh/src/zig/build/CMakeFiles/zig2.dir/compiler_depend.internal".
> Consolidate compiler generated dependencies of target zig2
> /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/zig2.dir/build.make CMakeFiles/zig2.dir/build
> [73%] Linking CXX executable zig2
> /opt/homebrew/Cellar/cmake/3.27.1/bin/cmake -E cmake_link_script CMakeFiles/zig2.dir/link.txt --verbose=on
> /Library/Developer/CommandLineTools/usr/bin/c++ -O3 -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-stack_size,0x10000000 CMakeFiles/zig2.dir/zig2.c.o CMakeFiles/zig2.dir/compiler_rt.c.o -o zig2 -L/Users/hh/local/llvm19-assert/lib -Wl,-rpath,/Users/hh/local/llvm19-assert/lib zigcpp/libzigcpp.a /opt/homebrew/opt/llvm/lib/libclangFrontendTool.a /opt/homebrew/opt/llvm/lib/libclangCodeGen.a /opt/homebrew/opt/llvm/lib/libclangFrontend.a /opt/homebrew/opt/llvm/lib/libclangDriver.a /opt/homebrew/opt/llvm/lib/libclangSerialization.a /opt/homebrew/opt/llvm/lib/libclangSema.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerFrontend.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerCheckers.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerCore.a /opt/homebrew/opt/llvm/lib/libclangAnalysis.a /opt/homebrew/opt/llvm/lib/libclangASTMatchers.a /opt/homebrew/opt/llvm/lib/libclangAST.a /opt/homebrew/opt/llvm/lib/libclangParse.a /opt/homebrew/opt/llvm/lib/libclangAPINotes.a /opt/homebrew/opt/llvm/lib/libclangBasic.a /opt/homebrew/opt/llvm/lib/libclangEdit.a /opt/homebrew/opt/llvm/lib/libclangLex.a /opt/homebrew/opt/llvm/lib/libclangARCMigrate.a /opt/homebrew/opt/llvm/lib/libclangRewriteFrontend.a /opt/homebrew/opt/llvm/lib/libclangRewrite.a /opt/homebrew/opt/llvm/lib/libclangCrossTU.a /opt/homebrew/opt/llvm/lib/libclangIndex.a /opt/homebrew/opt/llvm/lib/libclangToolingCore.a /opt/homebrew/opt/llvm/lib/libclangExtractAPI.a /opt/homebrew/opt/llvm/lib/libclangSupport.a /opt/homebrew/opt/llvm/lib/libclangInstallAPI.a /opt/homebrew/opt/llvm/lib/libclangSema.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerFrontend.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerCheckers.a /opt/homebrew/opt/llvm/lib/libclangStaticAnalyzerCore.a /opt/homebrew/opt/llvm/lib/libclangAnalysis.a /opt/homebrew/opt/llvm/lib/libclangASTMatchers.a /opt/homebrew/opt/llvm/lib/libclangAST.a /opt/homebrew/opt/llvm/lib/libclangParse.a /opt/homebrew/opt/llvm/lib/libclangAPINotes.a /opt/homebrew/opt/llvm/lib/libclangBasic.a /opt/homebrew/opt/llvm/lib/libclangEdit.a /opt/homebrew/opt/llvm/lib/libclangLex.a /opt/homebrew/opt/llvm/lib/libclangARCMigrate.a /opt/homebrew/opt/llvm/lib/libclangRewriteFrontend.a /opt/homebrew/opt/llvm/lib/libclangRewrite.a /opt/homebrew/opt/llvm/lib/libclangCrossTU.a /opt/homebrew/opt/llvm/lib/libclangIndex.a /opt/homebrew/opt/llvm/lib/libclangToolingCore.a /opt/homebrew/opt/llvm/lib/libclangExtractAPI.a /opt/homebrew/opt/llvm/lib/libclangSupport.a /opt/homebrew/opt/llvm/lib/libclangInstallAPI.a /opt/homebrew/opt/lld/lib/liblldMinGW.dylib /opt/homebrew/opt/lld/lib/liblldELF.dylib /opt/homebrew/opt/lld/lib/liblldCOFF.dylib /opt/homebrew/opt/lld/lib/liblldWasm.dylib /opt/homebrew/opt/lld/lib/liblldMachO.dylib /opt/homebrew/opt/lld/lib/liblldCommon.dylib /Users/hh/local/llvm19-assert/lib/libLLVMWindowsManifest.a /Users/hh/local/llvm19-assert/lib/libLLVMXRay.a /Users/hh/local/llvm19-assert/lib/libLLVMLibDriver.a /Users/hh/local/llvm19-assert/lib/libLLVMDlltoolDriver.a /Users/hh/local/llvm19-assert/lib/libLLVMTextAPIBinaryReader.a /Users/hh/local/llvm19-assert/lib/libLLVMCoverage.a /Users/hh/local/llvm19-assert/lib/libLLVMLineEditor.a /Users/hh/local/llvm19-assert/lib/libLLVMSandboxIR.a /Users/hh/local/llvm19-assert/lib/libLLVMXCoreDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMXCoreCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMXCoreDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMXCoreInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMX86TargetMCA.a /Users/hh/local/llvm19-assert/lib/libLLVMX86Disassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMX86AsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMX86CodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMX86Desc.a /Users/hh/local/llvm19-assert/lib/libLLVMX86Info.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyUtils.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMWebAssemblyInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMVEDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMVEAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMVECodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMVEDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMVEInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMSystemZDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMSystemZAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMSystemZCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMSystemZDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMSystemZInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMSparcDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMSparcAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMSparcCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMSparcDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMSparcInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVTargetMCA.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMRISCVInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMPowerPCDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMPowerPCAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMPowerPCCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMPowerPCDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMPowerPCInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMNVPTXCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMNVPTXDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMNVPTXInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMMSP430Disassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMMSP430AsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMMSP430CodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMMSP430Desc.a /Users/hh/local/llvm19-assert/lib/libLLVMMSP430Info.a /Users/hh/local/llvm19-assert/lib/libLLVMMipsDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMMipsAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMMipsCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMMipsDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMMipsInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMLoongArchDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMLoongArchAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMLoongArchCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMLoongArchDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMLoongArchInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMLanaiDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMLanaiCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMLanaiAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMLanaiDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMLanaiInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMHexagonDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMHexagonCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMHexagonAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMHexagonDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMHexagonInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMBPFDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMBPFAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMBPFCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMBPFDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMBPFInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMAVRDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMAVRAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMAVRCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMAVRDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMAVRInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMARMDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMARMAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMARMCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMARMDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMARMUtils.a /Users/hh/local/llvm19-assert/lib/libLLVMARMInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUTargetMCA.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUDesc.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUUtils.a /Users/hh/local/llvm19-assert/lib/libLLVMAMDGPUInfo.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64Disassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64AsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64CodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64Desc.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64Utils.a /Users/hh/local/llvm19-assert/lib/libLLVMAArch64Info.a /Users/hh/local/llvm19-assert/lib/libLLVMOrcDebugging.a /Users/hh/local/llvm19-assert/lib/libLLVMOrcJIT.a /Users/hh/local/llvm19-assert/lib/libLLVMWindowsDriver.a /Users/hh/local/llvm19-assert/lib/libLLVMMCJIT.a /Users/hh/local/llvm19-assert/lib/libLLVMJITLink.a /Users/hh/local/llvm19-assert/lib/libLLVMInterpreter.a /Users/hh/local/llvm19-assert/lib/libLLVMExecutionEngine.a /Users/hh/local/llvm19-assert/lib/libLLVMRuntimeDyld.a /Users/hh/local/llvm19-assert/lib/libLLVMOrcTargetProcess.a /Users/hh/local/llvm19-assert/lib/libLLVMOrcShared.a /Users/hh/local/llvm19-assert/lib/libLLVMDWP.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoLogicalView.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoGSYM.a /Users/hh/local/llvm19-assert/lib/libLLVMOption.a /Users/hh/local/llvm19-assert/lib/libLLVMObjectYAML.a /Users/hh/local/llvm19-assert/lib/libLLVMObjCopy.a /Users/hh/local/llvm19-assert/lib/libLLVMMCA.a /Users/hh/local/llvm19-assert/lib/libLLVMMCDisassembler.a /Users/hh/local/llvm19-assert/lib/libLLVMLTO.a /Users/hh/local/llvm19-assert/lib/libLLVMPasses.a /Users/hh/local/llvm19-assert/lib/libLLVMHipStdPar.a /Users/hh/local/llvm19-assert/lib/libLLVMCFGuard.a /Users/hh/local/llvm19-assert/lib/libLLVMCoroutines.a /Users/hh/local/llvm19-assert/lib/libLLVMipo.a /Users/hh/local/llvm19-assert/lib/libLLVMVectorize.a /Users/hh/local/llvm19-assert/lib/libLLVMLinker.a /Users/hh/local/llvm19-assert/lib/libLLVMInstrumentation.a /Users/hh/local/llvm19-assert/lib/libLLVMFrontendOpenMP.a /Users/hh/local/llvm19-assert/lib/libLLVMFrontendOffloading.a /Users/hh/local/llvm19-assert/lib/libLLVMFrontendOpenACC.a /Users/hh/local/llvm19-assert/lib/libLLVMFrontendHLSL.a /Users/hh/local/llvm19-assert/lib/libLLVMFrontendDriver.a /Users/hh/local/llvm19-assert/lib/libLLVMExtensions.a /Users/hh/local/llvm19-assert/lib/libLLVMDWARFLinkerParallel.a /Users/hh/local/llvm19-assert/lib/libLLVMDWARFLinkerClassic.a /Users/hh/local/llvm19-assert/lib/libLLVMDWARFLinker.a /Users/hh/local/llvm19-assert/lib/libLLVMCodeGenData.a /Users/hh/local/llvm19-assert/lib/libLLVMGlobalISel.a /Users/hh/local/llvm19-assert/lib/libLLVMMIRParser.a /Users/hh/local/llvm19-assert/lib/libLLVMAsmPrinter.a /Users/hh/local/llvm19-assert/lib/libLLVMSelectionDAG.a /Users/hh/local/llvm19-assert/lib/libLLVMCodeGen.a /Users/hh/local/llvm19-assert/lib/libLLVMTarget.a /Users/hh/local/llvm19-assert/lib/libLLVMObjCARCOpts.a /Users/hh/local/llvm19-assert/lib/libLLVMCodeGenTypes.a /Users/hh/local/llvm19-assert/lib/libLLVMIRPrinter.a /Users/hh/local/llvm19-assert/lib/libLLVMInterfaceStub.a /Users/hh/local/llvm19-assert/lib/libLLVMFileCheck.a /Users/hh/local/llvm19-assert/lib/libLLVMFuzzMutate.a /Users/hh/local/llvm19-assert/lib/libLLVMScalarOpts.a /Users/hh/local/llvm19-assert/lib/libLLVMInstCombine.a /Users/hh/local/llvm19-assert/lib/libLLVMAggressiveInstCombine.a /Users/hh/local/llvm19-assert/lib/libLLVMTransformUtils.a /Users/hh/local/llvm19-assert/lib/libLLVMBitWriter.a /Users/hh/local/llvm19-assert/lib/libLLVMAnalysis.a /Users/hh/local/llvm19-assert/lib/libLLVMProfileData.a /Users/hh/local/llvm19-assert/lib/libLLVMSymbolize.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoBTF.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoPDB.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoMSF.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoDWARF.a /Users/hh/local/llvm19-assert/lib/libLLVMObject.a /Users/hh/local/llvm19-assert/lib/libLLVMTextAPI.a /Users/hh/local/llvm19-assert/lib/libLLVMMCParser.a /Users/hh/local/llvm19-assert/lib/libLLVMIRReader.a /Users/hh/local/llvm19-assert/lib/libLLVMAsmParser.a /Users/hh/local/llvm19-assert/lib/libLLVMMC.a /Users/hh/local/llvm19-assert/lib/libLLVMDebugInfoCodeView.a /Users/hh/local/llvm19-assert/lib/libLLVMBitReader.a /Users/hh/local/llvm19-assert/lib/libLLVMFuzzerCLI.a /Users/hh/local/llvm19-assert/lib/libLLVMCore.a /Users/hh/local/llvm19-assert/lib/libLLVMRemarks.a /Users/hh/local/llvm19-assert/lib/libLLVMBitstreamReader.a /Users/hh/local/llvm19-assert/lib/libLLVMBinaryFormat.a /Users/hh/local/llvm19-assert/lib/libLLVMTargetParser.a /Users/hh/local/llvm19-assert/lib/libLLVMTableGen.a /Users/hh/local/llvm19-assert/lib/libLLVMSupport.a /Users/hh/local/llvm19-assert/lib/libLLVMDemangle.a -lm -lz -lzstd
> ld: library not found for -lzstd
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make[2]: *** [zig2] Error 1
> make[1]: *** [CMakeFiles/zig2.dir/all] Error 2
> make: *** [all] Error 2
> 
> ```

The `/Library/Developer/CommandLineTools/usr/bin/c++` invocation does not include the `/opt/homebrew/opt/zstd` path, and at this point I’m lost without spending a lot of time learning cmake intricacies.

Does anyone quickly see what configuration to cmake I’m missing to get the local source build past this point?

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [October 15, 2024, 5:50am UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/2 "2024-10-15T05:50:00Z")

</div>

Welcome to ziggit @mark-rushakoff 🙂

Try to build with the static version of zstd adding `-DZIG_STATIC_ZSTD=ON`.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [October 15, 2024, 6:04am UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/3 "2024-10-15T06:04:28Z")

</div>

From the output, only the following path is added: `-L/Users/hh/local/llvm19-assert/lib`  
Try to reduce the prefix paths to:  
`-DCMAKE_PREFIX_PATH="$HOME/local/llvm19-assert;$(brew --prefix zstd)"`

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [October 15, 2024, 2:05pm UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/4 "2024-10-15T14:05:01Z")

</div>

> [@mark-rushakoff](#):
>
> Does anyone quickly see what configuration to cmake I’m missing to get the local source build past this point?

Welcome to Ziggit @mark-rushakoff. [#20806](https://github.com/ziglang/zig/issues/20806) on the issue board has some lore which should be enough to get you started.

I did say in that issue that I was going to do some clean-slate reproductions of the various steps to boil them down to the minimal necessary, and add that information to the wiki. Which I haven’t done. Sorry about that.

---

<div class="post-metadata">

**Author:** ![mark-rushakoff](https://ziggit.dev/user_avatar/ziggit.dev/mark-rushakoff/32/3551_2.png) [@mark-rushakoff](https://ziggit.dev/u/mark-rushakoff)\
**Post date:** [October 16, 2024, 3:05am UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/5 "2024-10-16T03:05:11Z")

</div>

Thanks @dimdin, this was the missing flag. The vanilla command (using the homebrew-installed llvm, not doing the local checkout of llvm) works when I add only that.

I ran

```shell
$ cmake .. -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="$(brew --prefix llvm@19);$(brew --prefix lld);$(brew --prefix zstd)" -DZIG_STATIC_ZSTD=ON
$ make -j install/local
# printed several C warnings, then printed many ld warnings like:
# ld: warning: object file (/opt/homebrew/opt/llvm/lib/libclangDriver.a(Action.cpp.o)) was built for newer macOS version (14.0) than being linked (13.3)
# But it completed successfully in about 16 minutes on my 2022 Mac Studio.
$ ./stage3/bin/zig version
0.14.0-dev.1914+1efc9c149

```

> [@mnemnion](#):
>
> I did say in that issue that I was going to do some clean-slate reproductions of the various steps to boil them down to the minimal necessary, and add that information to the wiki. Which I haven’t done. Sorry about that.

I’m going to try and add the ` -DZIG_STATIC_ZSTD=ON` flag to the building from source wiki page, and I’ll backlink to this discussion in the comment. I am pretty sure I had a vanilla initial state aside from a few `brew install` commands.

I think `brew install llvm lld zstd cmake` is sufficient, but I don’t have a fresh system where I can just install homebrew and run that before attempting to build zig from source.

---

<div class="post-metadata">

**Author:** ![aaron-ang](https://ziggit.dev/user_avatar/ziggit.dev/aaron-ang/32/6992_2.png) [@aaron-ang](https://ziggit.dev/u/aaron-ang)\
**Post date:** [November 22, 2025, 8:16pm UTC](https://ziggit.dev/t/help-with-building-zig-from-source-cmake-on-macos-with-homebrew-trouble-linking-zstd/6381/6 "2025-11-22T20:16:32Z")

</div>

Hi there, I am trying to build Zig locally from source on macOS with the given command in the wiki:

```zig
cmake .. -DZIG_STATIC_LLVM=ON -DZIG_STATIC_ZSTD=ON -DCMAKE_PREFIX_PATH="$(brew --prefix llvm@21);$(brew --prefix lld@21);$(brew --prefix zstd)/lib"

```

However, `make install` fails at the `zig2` build stage.

```zig
ld: multiple errors: could not parse bitcode object file /opt/homebrew/opt/llvm/lib/libclangCodeGen.a(X86.cpp.o): 'Unknown attribute kind (102) (Producer: 'LLVM21.1.6' Reader: 'LLVM APPLE_1_1700.4.4.1_0')', using libLTO version 'LLVM version 17.0.0' in '/opt/homebrew/opt/llvm/lib/libclangCodeGen.a(X86.cpp.o)'; ...

```

It seems like the build script is not using Homebrew’s LLVM 21 LTO library. Is there an additional flag that I need to pass?

Edit: trying to use zig-bootstrap instead

- [Unable to compile master Zig from source on MacOS - #2 by Justus2308](https://ziggit.dev/t/unable-to-compile-master-zig-from-source-on-macos/12248/2)
- [Building Zig From Source · ziglang/zig Wiki · GitHub](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source#option-b-use-a-pre-built-zig-binary)
