Quite generally can anyone point me to any ROOT 6 example projects that just work? No writing CMake files or googling Visual Studio build settings, just an actual example project.
Thereafter, can anyone point me to a project that uses Cling (ideally with CMake on Ubuntu) so I can define my own SIGNAL/SLOT functionality (I just want a button or TTimer that can toggle a boolean!)
cmake_minimum_required(VERSION 3.16)
project(TestRoot VERSION 0.1.0 LANGUAGES C CXX)
set (CMAKE_CXX_STANDARD 17)
set(SOURCE main.cpp)
add_executable(TestRoot ${SOURCE})
target_include_directories(TestRoot PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
$ENV{ROOTSYS}/include)
target_link_libraries(TestRoot
$ENV{ROOTSYS}/lib/libProofPlayer.so
$ENV{ROOTSYS}/lib/libmapDict.so
$ENV{ROOTSYS}/lib/libXrdHttpUtils.so
...
$ENV{ROOTSYS}/lib/libRooFitZMQ.so
$ENV{ROOTSYS}/lib/libXrdCksCalczcrc32-5.so
$ENV{ROOTSYS}/lib/libImt.so)
find_package(ROOT) seems to have no impact on the CMake file.
Attempting to add a button (or do anything that would require Cint in ROOT 5) gives me a runtime error:
Fatal in <operator new>: with std::align_val_t is not implemented yet
aborting
#0 0x00007f3a960ea45a in __GI___wait4 (pid=28528, stat_loc=stat_loc
entry=0x7ffed8f92f88, options=options
...
#16 0x00007f3a975b7ff6 in dl_open_worker (a=0x7ffed8f960c0) at ./elf/dl-open.c:808
...
#20 0x00007f3a960906bc in dlopen_doit (a=a
entry=0x7ffed8f96330) at ./dlfcn/dlopen.c:56
...
#29 0x000055a3ffade823 in main (argc=1, argv=0x7ffed8f966b8) at ...
Aborted (core dumped)
I have manually run ${ROOTSYS}/bin/rootcling -v -f mainframecling.cpp -c mainframe.h mainframe_Linkdef.h which generates the files mainframecling_rdict.pcm and mainframecling.cpp.
I have attempted to add them to my CMake file but Iâm unclear how and nothing I tried resolved anything.
EDIT:
as long as root is available in your environment when you run the cmake configuration, find_package(ROOT) should work. It should also produce output that tells you what it found.
Make sure to use the same C++ standard for your project as the one ROOT was built with, changing C++ standards can introduce problems.
Itâs best practice to use targets such as ROOT::ROOTDataFrame instead of explicitly passing $ENV{ROOTSYS}/lib/libImt.so because targets bring with them their own usage requirements (include directories, libraries to link, etc.).
Hi Enrico! Thank you so much for the response especially since I can see you are a ROOT author/contributor and my query is extremely basic!
So from a (near) fresh Ubuntu install, I have opened a terminal and performed:
cd
sudo apt-get install git
sudo snap install root-framework
git clone https://github.com/eguiraud/rdf-benchmarks.git
cd rdf-benchmarks
cmake .
This gives me the error
-- Looking for ROOT
CMake Error at src/CMakeLists.txt:2 (find_package):
By not providing "FindROOT.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ROOT", but
CMake did not find one.
Could not find a package configuration file provided by "ROOT" with any of
the following names:
ROOTConfig.cmake
root-config.cmake
Add the installation prefix of "ROOT" to CMAKE_PREFIX_PATH or set
"ROOT_DIR" to a directory containing one of the above files. If "ROOT"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/***/rdf-benchmarks/CMakeFiles/CMakeOutput.log".
The error is comprehensive but I am not sure how to execute the fix? Looking at your EDIT 2, I think I have a good chance of getting ROOTCling to work in CMake once I can get this first example to work! For the âintegrating ROOT into CMake projectsâ link, it looks like the newer âtargetâ CMake features arenât being used, and me blindly following the tutorial there didnât resolve my issues.
Googling relevant ROOT forum posts about the issue sends me to the following dead link: h t t p s : / / r o o t . c e r n / h o w / i n t e g r a t e - r o o t - m y - p r o j e c t - c m a k e /
(new users canât post links)
I think itâs Snap thatâs making things more difficult for you â as far as I know Snap tries to sandbox each package so that might be the reason find_package(ROOT) fails to find ROOT.
In the annoucement post the author of the Snap package mentions, under âCreating Independent Executablesâ, that it might not be possible (but Iâm not 100% sure if thatâs your case, letâs ping @James-Carroll ).
it looks like the newer âtargetâ CMake features arenât being used
To unblock you in the meanwhile I would suggest that you download and use a pre-compiled binary as described at Installing ROOT - ROOT instead of the Snap package.
Thereâs some limited facility to use CMake with the ROOT snap; but it involves using the CMake bundled with the snap rather than the one on the system. Itâll only have access to libraries bundled with the Snap but for simple cases works fairly well. (It even manages to build Geant4 for example, not that Iâd recommend it for proper use).
You can invoke it with root-framework.cmake, it takes all the parameters CMake would usually take; and then will be running CMake in the snaps container against the snaps libraries.
With the binary output, youâd be able to use root-framework.run ./myapplication.a for example, which again, runs in the Snap container against the snaps libs.
Itâs not something I tell people about often because while itâs useful in certain contexts, itâs admittedly very non-functional in a lot of other contexts. E.G, if you use sudo apt install mylibrary-dev for any arbitrary package on the host system, the snap canât see it.
Thereâs also a downside that the ABI stability of ROOT isnât guaranteed and the Snap automatically updates, when it does, youâd have to rebuild your projects and it might not be clear whatâs broken when trying. But you can stop the snap updating with sudo snap refresh --hold root-framework.
For educational use or use in certain contexts this might be all you need, but if you were planning on more advanced projects, Iâd agree that the pre-compiled binaries (or Docker/Conda) could suit your use case better.
Hopefully if you give it a try with the wrappers, you might find some more success.
wget https://root.cern/download/root_v6.28.04.Linux-centos8-x86_64-gcc8.5.tar.gz
tar -xzvf root_v6.28.04.Linux-centos8-x86_64-gcc8.5.tar.gz
source root/bin/thisroot.sh # also available: thisroot.{csh,fish,bat}
https://github.com/eguiraud/root_dictionaries_tutorial.git
cd root_dictionaries_tutorial/with_cmake
cmake . && cmake --build .
Then after getting the error:
warning: #warning "The C++ standard in this build does not match ROOT configuration (201402L); this might cause unexpected issues" [-Wcpp]
30 | # warning "The C++ standard in this build does not match ROOT configuration (201402L); this might cause unexpected issues"
| ^~~~~~~
I went nano CMakeLists.txt and included
the line
set(CMAKE_CXX_STANDARD 14)
after project(readwrite_twoints CXX)
cmake . && cmake --build . now compiles the program but I get the following runtime error when I run ./readwrite_twoints
ERROR in cling::CIFactory::createCI(): cannot extract standard library include paths!
Invoking:
LC_ALL=C ccache -xc++ -E -v /dev/null 2>&1 | sed -n -e '/^.include/,${' -e '/^ \/.*++/p' -e '}'
Results was:
With exit code 0
Written TwoInts(1, 2)
Read TwoInts(1, 2)
I see you downloaded the centos8 package but in the first post you mention you are on Ubuntu.
That might be the reason behind that last error message (the first error message is about the need to match the C++ standard of the application with the C++ standard of ROOT, as you figured out).
Modifying the CMakeLists.txt file wasnât necessary in the end. Iâm on Ubuntu 22 but for any other OS, modify the above by navigating to the latest stable release from Releases - ROOT. It was also not necessary to go into .profile or .bashrc and update any environment variables to get this far (although there may be benefits to doing so).
So in the end the only ârealâ issue was the Snap package sandboxing IIUC.
About .profile and .bashrc: the only thing people usually put there is the source thisroot.sh command so they donât have to type it every time they start a new terminal.
I would say the links to your Github projects are also super valuable! Theyâre simple but theyâre not trivial to write if you donât know what to Google