libclang shared library that exports all symbols exports only the symbols needed by the C API. This is in contrast to that exports all symbols from the LLVM static libraries. Would it be useful to provide a libclang shared library that exports all symbols for use by tools that use Clang’s (admittedly non-backwards-compatible) C++ API?

We can either:

  1. Add a new shared library ( that is built based on a CMake option.
  2. Export all symbols from the current We’d have to also include a few additional libraries such as libClangAnalysis. Tools using the C API are still restricted to the stable interface if they use the clang-c headers.

There are a few Clang-based tools used by Android’s build system (1, 2) that use the C++ API. They are built using Android build rules but need to link against Android’s Clang toolchain that’s built with CMake. We don’t want to include the libclang static libraries with the toolchain for space considerations, and also to avoid exposing Clang’s build internals (internal library dependences and changes to them) to downstream tools.

Do other Clang/LLVM toolchain maintainers face similar issues and have solutions that are applicable here?


Ping for any thoughts on this proposal…

Why do you need to mix C++ symbols with what libclang exports?

My reasoning was that the C/C++ difference was already imposed by the headers included by a user. But I also see why limiting the exported symbols can catch user errors.

Doesn’t it make sense to have separate instead? I also think there’s already a possibility to build such library by providing some LLVM flags.

I think you mean LLVM_ENABLE_SHARED? That builds each individual library (libclangAST, libclangDriver etc) as shared libraries, rather than producing a single shared library. I am not aware of any other option that can help.

To clarify my proposal, I’ve uploaded a patch ( that adds this new library. The library is named libclang-cxx in that patch - which I think is slightly more informative than libclang-full.

Please add comments in the patch or to this discussions.


I think I meant CLANG_PLUGIN_SUPPORT flag which enables export_executable_symbols(clang) in tools\clang\tools\driver\CMakeLists.txt

Probably in combination with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS.


Hi Ivan,

Thanks for pointing out Clang plugins as a viable alternative for my proposal. We had considered writing the tools as a plugin but decided against it - due to some rough edges with Android’s build system.

For now, we decided to carry build rules for the proposed library in downstream. I’ve updated my change ( to make it more general, and will leave it open in case there’s more interest to revive it in the future.


Here's my edited comment from the differential review, I think it's a great
idea but there are fundamental flaws and inconsistency with it:

I'm in support as long as it's a configuration option defaulting similar to
LLVM's one. Should likely follow the same naming convention as LLVM, ie. clang-
shlib. Clang has a lot of tools it ships with especially if you consider extras,
I think this is one of the cases where an exception for can be
made as long as it's not a default. It would make builds of things like clang-
tidy much faster without requiring a fully shared library build.

IIRC libclang is a tool in itself, and is not mandatory for Clang driver tool
build which is the most fundamental part to most customers, while this new
library is not. There are a lot of things the downstream discussions have not
covered it seems since this only accounts for for a full
Clang+Tools+ARCMT+StaticAnalyzer+Extra (ie. tidy, include fixer) build. This
just fails to account for so much. The pairing of libclang and the new shared
library defeats the entire point of it altogether, since libclang is not
required by the driver. Nor by most in-tree tools.

(Not sure if we should continue the discussion here or in the review. I think the mailing list makes more sense because cfe-dev is likely read by more people than cfe-commits).

I want to clarify that I mixed terms in a misleading way. By “Clang tools”, I meant Clang-based out-of-tree tools (that currently need to use or libclang*.a). So the new shared library will be similar to the existing

I’m not sure if there’s enough value in linking tools in clang/tools and clang/tools/extra with a common single shared object. If there is, I’ll be willing to implement those as well. This will ultimately benefit us as well, by making the toolchains maintained by our team smaller.