Zig - Error while loading shared libraries: libclang-cpp.so

Written by Lyoneel on in troubleshooting
 2 mins

Zig - Error while loading shared libraries: libclang-cpp.so

I found this problem trying to build a Zig program first time

My problem starts here:

web@lyoneel.dev : zsh — Konsole
  • $ zig build-exe my-zig-program.zig
  • zig: error while loading shared libraries: libclang-cpp.so
 

The problem is the packages clang and llvm-libs currently installed are outdated, you may have other programs that relies on older versions of these packages, that’s where the problem begins. This means you cannot update in normal way, you have force-remove packages.

Let’s deal with it!

At this point I have clang v14 and llvm-libs14 installed, you may have another version like 13, normally ends with the version number e.g.: clang14 clang13 etc.

To force remove clang and llvm-libs use the following command:

sudo pacman -Rdd clang llvm-libs14

Not by mistake I put clang instead of clang14 this is because when I installed this package was the latest version, that means no version suffix.

Then I add an old clang version, in my case is needed clang14 for other dependencies, and clang v15 for Zig.

sudo pacman -Sy clang14 clang

If you are not sure which version is needed for other packages, you can play safe and add older versions of the package, at the time of writing is available clang13.

Actualizamos llvm-libs:

sudo pacman -Sy lib32-llvm-libs llvm-libs llvm14-libs

You should now try again your zig build, It should be fine.

web@lyoneel.dev : zsh — Konsole
  • $ zig build-exe my-zig-program.zig
  • "Hello World"
 

Thanks for reading!

Namaste.