I’ve been trying to compile Cling with c++17 (as opposed to the default 14) with Windows SDK version 10.0.19041.0 to target Windows 10.0.18363 (msvc 2019) via
following the instructions here https://root.cern.ch/cling-build-instructions … After making a couple changes in (STLExtras.h for example) it’ll compile; however, although Clang 5 ‘support’ c++17, it seems like std::any etc weren’t introduced into LLVM until 7.0. I was trying to compile Cling with current (10) LLVM & Clang, but that gives a ton of errors. Is there any documentation as to what exactly is changed in clang to make it compatible with Cling? I tried running a file diff after doing cling-patches, but it was a lot … so figured I’d ask if anyone had any suggestions or something I missed. Thanks!
No wait there are a couple of things I don’t understand.
std::any will be picked up from MSVC, not from clang. cling is just linking against clang, and serves as the “language processing engine” (replacing the compiler); the standard library is that of MSVC.
We build llvm with C++17 without problems on Linux. I believe MSVC always uses the newest standard, @bellenot ? So I don’t understand what you’d have to “fix” in STLExtras.h.
Now the most important part: what is the failure you see?
I’ll copy and paste what isn’t working as I want it to …
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ std::cout << "nothing included";
input_line_3:2:7: error: no member named 'cout' in namespace 'std'
std::cout << "nothing included";
~~~~~^
[cling]$ #include <Windows.h>
[cling]$ #include <iostream>
[cling]$ #include <any>
[cling]$ #include <string>
[cling]$ std::string testString = "This is a string.";
[cling]$ std::any testAny = testString;
input_line_9:2:7: error: no type named 'any' in namespace 'std'
std::any testAny = testString;
~~~~~^
[cling]$ std::cout << testString;
This is a string.
[cling]$ namespace one::two {int testInt = 7;}
input_line_11:1:14: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace one::two {int testInt = 7;}
^~~~~
{ namespace two }
[cling]$
As for STLExtras.h … the llvm version included in the source pointed to by https://root.cern.ch/cling-build-instructions uses std::unary_function and std::binary_function (removed from c++17), so my build was failing when I passed it CMAKE_CXX_STANDARD=17.
though now I’m wondering if I’m missing some other flag … I deleted the directory but cling was compiling in MSVC with c++17 … it’s grabbing the header but clang is throwing that -Wc++17-extensions error.
namespace std {
template<class Arg1, class Arg2, class Result>
struct binary_function
{
using first_argument_type = Arg1;
using second_argument_type = Arg2;
using result_type = Result;
};
template <typename ArgumentType, typename ResultType>
struct unary_function
{
using argument_type = ArgumentType;
using result_type = ResultType;
};
}
There were only a couple compilation errors after that, mostly fixed by removing a bunch of #include <unistd.h> instances. I never noticed that c++14 hardcoded in the cling cmakelists.txt … I’ll have to try again since that makes sense with the error I got.
that didn’t work. as expected, pragma silencing the -Wc++17-extensions error executed the code just removed the warning but the code still did not execute.
Can I build Root as c++17 and use Cling from there?
Also - the install guide references modifications to llvm/clang that were made to make cling run, but I couldn’t find any detail. Is that listed anywhere? Thanks!
it’s probably because you’re internal? maybe I’m missing something but I don’t think it’s public. Closest I could find is https://root.cern/download/ but I don’t see any documentation of the patches in there.
Apologies I think we were talking about different things … I can download your repo and compare it to vanilla llvm to see what changes were made, I was just wondering if there was any documentation of the changes.