libclang-static-build: a standalone, static libclang distro that works.

Hot take: has made ← a simple static build of libclang that allows you to bust your libtooling and other clang related code out of llvm build tree jail and api version hell.

One of my previous lives involved writing a lot of C++ and I became very opinionated on some practices in C++. For larger programs, I tended toward a java style that put an abstract base (ISomeObject) when appropriate in front of objects conferring nontrivial functionality (network protocol clients, db adapters, even coupling to the filesystem) and so wrote a tool that helped enforce these kinds of rules. I was pretty happy with the result but less so the workflow to build it; the official libtooling documentation basically tells you to build tooling programs in the llvm tree. When I’ve had the chance to recommend libtooling to someone to solve a problem (or to be like me and use my rules), I really can’t recommend it as a common workflow because of the lack of documentation for a normal dev workflow and the rate of change in the clang api… It’s a mess for anyone whose 9–5 isn’t packaging up clang for google or apple.

Enter .

It’s very self contained and you can incorporate it easily into cmake projects (and you’re probably building clang related stuff with cmake anyway).

While I’m not a cmake maven, using it went pretty simply

cmake_minimum_required(VERSION 3.13)

set(LIBCLANG_INSTALL "libclang-copied")
DOWNLOAD_DIR "libclang-static-build"
GIT_TAG "0cae8e85ef1ad951e1bb560e1eadcd64b2f0828e"



ExternalProject_Get_Property(libclang-static-build binary_dir)


add_dependencies(noglob libclang-static-build)
target_link_libraries(noglob "-L${binary_dir}" "-lclang_static_bundled" -lpthread)

Just a bit of hooking into libclang-static-build and you can ignore that your distro somehow manages to ship both with a libclang that’s newer than what you built with last time (with breaking api changes) but not new enough to take advantage of features you’ve recently read about in the docs.

An old programmer learning new tricks.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store