Hey Guys, Sorry for polluting this thread with endless posts (I just can’t find what i need to know )
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
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.
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_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CLING_MODULES_DIR})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} ${CLING_MODULES_DIR}") # use llvm's cmake scripts to load in the libraries
set(CLING_LIB_DIR ${CLING_DIR}/lib)
set(CLING_INCLUDE_DIR ${CLING_DIR}/include)
find_package(LLVM CONFIG REQUIRED )
add_definitions(${LLVM_DEFINITIONS})
set (CLING_LIBRARIES
# Readers despair; the order of these files -matter-
${CLING_LIB_DIR}/libclingMetaProcessor.a
${CLING_LIB_DIR}/libclingInterpreter.a
${CLING_LIB_DIR}/libclingUtils.a
${CLING_LIB_DIR}/libclangFrontend.a
${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
${CLING_LIB_DIR}/libclangParse.a
${CLING_LIB_DIR}/libclangSema.a
${CLING_LIB_DIR}/libclangBasic.a
${CLING_LIB_DIR}/libclangSerialization.a
${CLING_LIB_DIR}/libclangDriver.a
${CLING_LIB_DIR}/libclangEdit.a
${CLING_LIB_DIR}/libclangLex.a
${CLING_LIB_DIR}/libclangTooling.a
${CLING_LIB_DIR}/libclangAnalysis.a
${CLING_LIB_DIR}/libclangAST.a
${LLVM_AVAILABLE_LIBS}
)
include_directories(${CLING_INCLUDE_DIR})
add_executable(tcling main.cpp)
target_link_libraries(tcling ${CLING_LIBRARIES})
I am also trying to generate libCling.so
At the moment I end-up building root and removing everything but libCling.so and the 3 files it depends on.
Is there a way to get the shared library from a pure cling build?
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?
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 libCling.so via root6 on AlpineLinux but root6 need some patches.
FYI, while implementing the necessary build system changes to build libcling.so I ran into an issue with llvm’s build system. I’m waiting for them to merge my patch upstream.