How to proprly link cling into my executable with cmake?

Hey Guys, Sorry for polluting this thread with endless posts (I just can’t find what i need to know :frowning: )

I’ve got cling to compile, and now am trying to figure out how to link it with a test program

If i try linking all of the archive files that were produced from the compilation (llvm, clang, cling) I get 1000 lines of undefinded references. If i include nothing, I just get a couple of undefined references from cling, but if i include libclingInterpreter.a, and libclingMetaProcessor.a as libraries, I also get a boatload of undefined references frm clang and llvm

the closest thing i found that seems to be relevent is

However, I’m not quite sure where cling comes into the equation there

Could anybody send me a link or explain to me the procedure of properly linking cling [with cmake]?

Thanks in advance
and sorry if this thread is redundant


You’ll need to link cling, clang and llvm, in that order. There are even dependencies within each of these project that define the correct link order, e.g. for cling you want to link UserInterface, MetaProcessor and then Interpreter.

Have a look at what’s happening in tools/driver. This is where the cling binary gets linked, it should show you how to get this done.

Cheers, Axel.

Hey Axel,

So far, I’m not having that much dice, however, in hopes of reducing linking time I wanted to use shared objects

cmake ../src/ -DCMAKE_INSTALL_PREFIX:PATH=/home/d4nf/cling/prefix/ -DBUILD_SHARED_LIBS=ON

it compiled with no problems with clang as the target, however for cling, the story wasn’t so simple:

Would you have any idea what’s causing this problem?

I’ll post my solution once i find it. at least I know now that my problem isn’t a N! permutations :stuck_out_tongue:



yeah sorry I don’t think we ever tried that… Looks like you’re missing most of the dependencies here.

We only ever do this from static libs, building either a binary or one single shared lib out of all the static libs needed to run cling.

Cheers, Axel.

ok I managed to do it here’s my CMakeLists.txt file

readers be aware that my cling install looks like the following

the cling source is in /home/d4nf/cling/src
my out of source build is in /home/d4nf/cling/build
my install prefix directory is in /home/d4nf/cling/prefix

consider this code to use the boost license

    cmake_minimum_required(VERSION 3.0)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set (CLING_DIR /home/d4nf/cling/prefix)
set (CLING_MODULES_DIR ${CLING_DIR}/share/llvm/cmake)
message (${CLING_MODULES_DIR})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CLING_MODULES_DIR}") # use llvm's cmake scripts to load in the libraries
find_package(LLVM  CONFIG REQUIRED )

# Readers despair; the order of these files -matter-

${CLING_LIB_DIR}/libclangCodeGen.a # this and the above 3 cling .a's are necessary if the rest of llvm was compiled as .so's
                                   # you'd need to make a seperate copy of the cling source, remove the tools/cling
                                   #directory, and do a make install with


add_executable(tcling main.cpp)
target_link_libraries(tcling ${CLING_LIBRARIES})

Hi everyone,

I am also trying to generate
At the moment I end-up building root and removing everything but and the 3 files it depends on.
Is there a way to get the shared library from a pure cling build?

Thanks for your help!

Hi Hugues,

Correct, for stand-alone cling we don’t build a shared lib. You should be able to build it yourself, in your project, by simply linking the .a archives together into a .so. Would that be okay?

Cheers, Axel.

Thanks Axel for the hint.

I am certainly not a linking master although I did try my best.
Commands like:

gcc -shared -o -Wl,--whole-archive \
libclingMetaProcessor.a \
libclingInterpreter.a \
-Wl,--no-whole-archive \
libclingUtils.a \
libclangFrontend.a \
libclangCodeGen.a \
libclangParse.a \
libclangSema.a \
libclangBasic.a \
libclangSerialization.a \
libclangDriver.a \
libclangEdit.a \
libclangLex.a \
libclangAnalysis.a \
libclangAST.a \
`ls libLLVM*.a`

generate a sizeable file of 80megs but running ldd on them return all kinds of symbol unresolved error.

Let me know if I am missing something obvious.

If it is not a mainstream scenario enough I am ok sticking to building root6 and getting from there.

Thanks again!


  • I’ll add a target to the cling build system. No time scale, though… so I’d welcome a patch!
  • Please use llvm-config for linking the llvm libraries. You can have a look at what happens when building in ROOT.

Cheers. Axel.

Thanks Axel and thanks for the hints.

I did try my best at figuring out how is built in root6.
It looks like it is using root’s core/meta module here: …
and relies on …

At that point I was not able to connect more dots. I still have the energy to try more things.
I have a root6 debian docker image and a cling debian image with everything in place for those experiments. All ready to be toyed with on aws-ec2 with a large instance to compile quickly.

My motivation is eventually to get it running on Alpine Linux for a much smaller footprint. I have the llvm patches ready. I can get the cling executable when building cling.
I tried to build via root6 on AlpineLinux but root6 need some patches.


FYI, while implementing the necessary build system changes to build I ran into an issue with llvm’s build system. I’m waiting for them to merge my patch upstream.


Update: we have now.