ziglang/zig

Building with LLVM 10.0.1 installed via Homebrew fails

kubkon opened this issue ยท 11 comments

As reported by @jbsolomon-fw in #4799, when building on macOS with LLVM 10.0.1 installed via Homebrew, linker trips with the following error:

ld: library not found for -llibxml2.tbd

This seems like an upstream problem with llvm-config which reports the following required system libraries to link properly with LLVM:

$ llvm-config --system-libs
-lz -lcurses -lm -llibxml2.tbd

A temporary (and super hacky hack hack that makes me cringe) solution to the problem is to:

  1. Create a symbolic link /usr/local/lib/liblibxml2.tbd.dylib -> /usr/lib/libxml2.2.dylib
  2. Add /usr/local/lib to your dyld search path if it's not already there. The easiest way is to simply add LINK_FLAGS "-L/usr/local/lib" to zig0 and zig target properties in CMakeLists.txt:
set_target_properties(zig0 PROPERTIES
    COMPILE_FLAGS ${EXE_CFLAGS}
    LINK_FLAGS ${EXE_LDFLAGS}
    LINK_FLAGS "-L/usr/local/lib"
)

This should get everyone with LLVM 10.0.1 installed via Homebrew on macOS going for now.

Out of curiosity, I built upstream LLVM from source, and the future looks even bleaker, with the following output from llvm-config:

$ ./llvm-config --version
12.0.0git
$ ./llvm-config --system-libs
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libcurses.tbd -lm -llibz.tbd -llibxml2.tbd

I have now filed an upstream bug report: https://bugs.llvm.org/show_bug.cgi?id=47226

UPDATE: Good news, this patch https://reviews.llvm.org/D86134#2224990 fixes this in upstream. Now we need to figure out if there is any plan to backport it to 10.0.1 -> 10.0.1.1, otherwise we'll need to wait an entire release cycle again, and who knows what breaks next...

Try the solution..Still got failed.

Ohai! New to zig, and ran into the same build problem.

Got around it by replacing the broken lib reference in LLVM_LIBRARIES in the CMake config.

try

brew install --build-from-source llvm

or remove --system-libs and add -lm -lz -lcurses -lxml2 directly.

I just built successfully on my macos with llvm 10.0.1_1. No hacks or workarounds were needed. Closing since it appears to be fixed by homebrew.

Still failing on my mac w/ brew llvm 10.0.1_1.

The LLVM 11 release is imminent. Let's see what happens. Until it gets packaged up you'll have to make do with building from source or using the binary distribution available on ziglang.org.