Linking issue when building zig

I’m trying to build zig from source so I can debug this issue ICE: deref of null value in llvm.updateExports · Issue #20847 · ziglang/zig · GitHub.
With:

cmake .. -DZIG_STATIC_LLVM=ON -DCMAKE_PREFIX_PATH="$(brew --prefix llvm@18);$(brew --prefix zstd);$(brew --prefix z3)"
make

The build fails when trying to find z3 symbols:

[ 73%] Linking CXX executable zig2
error: undefined symbol: _xmlDocSetRootElement
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImpl17getMergedManifestEv
error: undefined symbol: _xmlFree
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImplD2Ev
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImplD2Ev
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImplD1Ev
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImplD1Ev
    note: referenced 8 more times
error: undefined symbol: _xmlDocDumpFormatMemoryEnc
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMWindowsManifest.a(WindowsManifestMerger.cpp.o):__ZN4llvm16windows_manifest21WindowsManifestMerger25WindowsManifestMergerImpl17getMergedManifestEv
error: undefined symbol: _Z3_mk_bvurem
    note: referenced by /opt/homebrew/opt/llvm/lib/libLLVMSupport.a(Z3Solver.cpp.o):__ZN12_GLOBAL__N_18Z3Solver8mkBVURemERKPKN4llvm7SMTExprES6_

...

z3 is installed:

$ brew --prefix z3
/opt/homebrew/opt/z3

Seems to be a LLVM issue.
Any idea what I’m missing?

See this thread: Building Zig from source for dummies?

This eventually worked:

cmake .. \
	-DCMAKE_PREFIX_PATH="$(brew --prefix zstd);$(brew --prefix llvm@18)" \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DZIG_NO_LIB=ON \
	-DZIG_STATIC_ZSTD=ON \
	-GNinja
ninja

Not sure if I need -DZIG_NO_LIB=ON nor what it does.

1 Like

From CMakeLists.txt:

Disable copying lib/ files to install prefix during the build phase