Wanted to share how to compile Cling for Windows on most recent MSVC 2022 Preview. I just did these steps below right now, on 2021.10.04 and got working cling.exe
.
As I’m a new user it is not allowed for me to put URLs (web links) in post, hence I modified URLs a bit to be non-clickable.
Just to remind - Cling home page is here https://rawgit.com/root-project/cling/master/www/build.html
-
Install MSVC 2022 (Preview or Community version is enough) from here
https://visualstudio.com/
and latest CMake from herehttps://cmake.org/download/
. Maybe other unix-like utils could be needed then install BinUtils, Git or other packages from Cygwin (https://cygwin.com/setup-x86_64.exe
)
git clone --branch=cling-patches --depth=1 http://root.cern.ch/git/llvm.git src
cd src
cd tools
git clone --depth=1 http://root.cern.ch/git/cling.git
git clone --branch=cling-patches --depth=1 http://root.cern.ch/git/clang.git
- Edit file
src/tools/cling/tools/CMakeLists.txt
by commenting out (adding#
) line#add_subdirectory(demo)
. Cling demo doesn’t compile now, it has unresolved symbol, we don’t need this demo, so can exclude it from build. Current error is
Creating library lib\cling-demo.lib and object lib\cling-demo.exp
cling-demo.exp : error LNK2001: unresolved external symbol "?setValueNoAlloc@internal@runtime@cling@@YAXPEAX00D_K@Z/EXPORT:?setValueNoAlloc@internal@runtime@cling@@YAXPEAX00DM@Z/EXPORT:cling_runtime_internal_throwIfInvalidPointer" (?setValueNoAlloc@internal@runtime@cling@@YAXPEAX00D_K@Z/EXPORT:?setValueNoAlloc@internal@runtime@cling@@YAXPEAX00DM@Z/EXPORT:cling_runtime_internal_throwIfInvalidPointer)
bin\cling-demo.exe : fatal error LNK1120: 1 unresolved externals
-
Edit file
src/tools/cling/lib/Utils/PlatformWin.cpp
by replacing#elif (_MSC_VER < 1930)
with#elif (_MSC_VER < 1990)
, i.e. increase version of MSVC, because MSVC-2022 is not yet supported. Maybe it will be supported later then you don’t need this change. Value1990
I made just too high, actual MSVC-2022 value is probably smaller, something like 1950, I don’t know exactly which, so I put 1990 to support versions in advance. -
Apply change taken from here
https://reviews.llvm.org/rG28a6713e107c9f878cb6c59db8548bb732dcc79d
(mentioned herehttps://reviews.llvm.org/D80433
) , i.e. edit filesrc\include\llvm\Support\ManagedStatic.h
by replacing#if !defined(_MSC_VER) || defined(__clang__)
with#if !defined(_MSC_VER) || (_MSC_VER >= 1925) || defined(__clang__)
-
Launch Visual Studio x64 Native Command Prompt (link to it is located either on Desktop or inside Windows Start Button / Visual Studio tab).
-
From Visual Studio command prompt build and install Cling
cmake -DCMAKE_INSTALL_PREFIX=c:/bin/cling/ -G Ninja ../src
cmake --build . --config Release --target cling --parallel
cmake --build . --config Release --target tools/cling/install --parallel
here change install prefix if you want other install location. This step also needs Ninja-Build, download it from here https://github.com/ninja-build/ninja/releases
. If you don’t want to use Ninja then remove -G Ninja
, this will use default Makefile target then.
- If build/install is successfull then now you can find and run
C:\bin\cling\bin\cling.exe
. Done!