Setting up an IDE for ROOT

Hello everyone,
I have worked a bit with ROOT macros and always used simple text editors. I would really love to setup an IDE, but I am not very familiar with similar tasks. I have found this post by @behrenhoff suggesting to use KDevelop, which would fit perfectly to my case since I’m already on Kubuntu and using KDE.

Now what I managed to do is creating an empty CMake project, and configuring it so that $ROOTSYS/include is added to the parser (via Project > Open Configuration… > Language Support). This makes KDevelop recognise ROOT classes so for example I get the auto-completion for TString, or I can make it insert automatically #include <TString.h>.

However, this doesn’t seem to be enough; first of all, the parser will give me errors when I try to use the TF1 class, like this:

#include <TF1.h>

int main() {
    TF1* func = new TF1();
}

This generates the following error in the parser

Unknown type name 'TF1'; did you mean 'Vc_1::TF1'?
'Vc_1::TF1' declared at TF1.h:211

(the same code works well if I work in interactive mode in ROOT, so I assume it’s some KDevelop error).
Also, if I try to build the project, this error occurs:

fatal error: TF1.h: no such file or directory

I am aware the ROOT forum is maybe not the best place where to ask to help for my issue; I am hoping that, in that case, someone can point me a more appropriate forum to ask, or some tutorial where I can learn how to deal with this.

Thanks in advance!

2 Likes

Well, after a lot of frustration trying to solve my problem, I have come to the conclusion I have no idea how compilers work and how linking libraries work. I just need to write and execute ROOT code though, and an extensive C++ course on compiling is not something I am willing to do. The only thing I am really searching for is parsing, auto-completion, code browsing and tools like these. At this point, I would settle for any other IDE, even if it’s not KDevelop, but I’ll need some step-by-step help or tutorial. I will be very glad to anyone who can help me.

FYI, I manage to develop and compile ROOT program with QtCreator. If you try this software, I should be able to help you to configure it. Maybe there is similar feature in KDevelop.

Thank you very much! I’ve just downloaded QtCreator and managed to run a simple Hello World program. How can I setup ROOT in it? Thanks!

Usually, if you use a .pro or CMake and you create a project, QtCreator will detect all the library automatically. (I do not have my laptop now so I cannot be more precise so far).
Let me know whether it works.

I am no expert about CMake. My CMakeLists.txt currently looks like the following:

cmake_minimum_required(VERSION 2.8)
project(myproj)
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
find_package(ROOT)
include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIR})
link_directories(${ROOT_LIBRARY_DIR})
add_executable(${PROJECT_NAME} "main.cpp")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${ROOT_LIBRARIES})

I only have some vague idea about what those lines do; this is basically a copypaste from other threads.

This does make QtCreator recognize ROOT classes after I #include the appropriate header file. (Is there any way to make QtCreator find automatically the header file to be included while I type, e.g., TH1F in my code?) However, if I try to run my project, which only has one file named main.cpp, which looks like this

#include <TH1.h>

int main()
{
    TH1F* histo = new TH1F();
    return 0;
}

I get

error while loading shared libraries: libMatrix.so.6.16: cannot open shared object file: No such file or directory

(I can confirm that $ROOTSYS/lib/libMatrix.so.6.16 is an existing file.)

Also, I suspect something may be broken about TF1.h. As soon as I try to #include it, I get a popup saying

Warning: The code model could not parse an included file, which might lead to slow or incorrect code completion and highlighting, for example.

gatherimplementation.h:73:21: error: 'vector_size' attribute requires an integer constant
main.cpp:1:1: note: in file included from /home/renyhp/Scrivania/vediamoseva/main.cpp:1:
main.cpp:2:10: note: in file included from /home/renyhp/Scrivania/vediamoseva/main.cpp:2:
TF1.h:27:10: note: in file included from /home/renyhp/Programmi/root/include/TF1.h:27:
TFormula.h:24:10: note: in file included from /home/renyhp/Programmi/root/include/TFormula.h:24:
Types.h:18:10: note: in file included from /home/renyhp/Programmi/root/include/Math/Types.h:18:
Vc:30:10: note: in file included from /home/renyhp/Programmi/root/include/Vc/Vc:30:
vector.h:35:11: note: in file included from /home/renyhp/Programmi/root/include/Vc/common/../vector.h:35:
vector.h:496:10: note: in file included from /home/renyhp/Programmi/root/include/Vc/sse/vector.h:496:
vector.tcc:32:10: note: in file included from /home/renyhp/Programmi/root/include/Vc/scalar/../common/../sse/vector.tcc:32:

My ROOT installation seems to be fine, though, since

TF1* func = new TF1()

in interactive mode doesn’t throw any error.

I may have spotted the problem with libMatrix.so.6.16. After inspecting ${ROOT_LIBRARIES} it seems like my CMake code is trying to link libMatrix.so instead of libMatrix.so.6.16. I have no idea how to fix that, though.

BTW I have managed to make everything run on KDevelop, too, but the same issue arises with this library. I am clearly doing something wrong with CMake, rather than the IDE

Update: I have tried to build and run multiple simple examples that I found on the internet (for example, the Event project), and it still gives me the same libMatrix error. At this point, it may not be CMake’s fault…

Update 2: I finally solved it. The problem was that $LD_LIBRARY_PATH was being unset every time a shell was opened because of security reasons. The solution was to add a .conf file in /etc/ld.so.conf.d/.

Thank you very much!

Sorry for being late to the party. A couple of comments:

You say “that business of compiling and linking is really complex! I’m not willing to spend time on learning it” and then go ahead and spend time implementing things which means you needed to learn it :slight_smile:

ROOT offers a top notch C++ interpreter that runs code at the speed of a compiled program. You can simply .x mycode.C - no need to compile or link. You can run root -l -b mycode.C to start it from a match / grid submission script. The goal of this is exactly to simplify the life of people who don’t want to learn compiler and linker flags!

That said, the canonical link for “how do I use CMake with ROOT and my own binary?” is https://root.cern.ch/how/integrate-root-my-project-cmake

Hello,

ROOT offers a top notch C++ interpreter that runs code at the speed of a compiled program. You can simply .x mycode.C - no need to compile or link. You can run root -l -b mycode.C to start it from a match / grid submission script. The goal of this is exactly to simplify the life of people who don’t want to learn compiler and linker flags!

I am perfectly aware of that. In fact, that was still the way I planned to execute my ROOT code. The point of this thread was to set up an IDE where coding for ROOT was easier than using a plain text editor. Obviously, for an IDE to be aware of the ROOT classes, it does need to parse the necessary ROOT code, and that was my goal. I was hoping to do that without spending time on learning about linking and compiling, but it seems like that wasn’t possible. I came up with this CMakeLists.txt file which I almost understand - I still didn’t take any course on compiling but I managed to get things together.

Point being,

the canonical link for “how do I use CMake with ROOT and my own binary?” is https://root.cern.ch/how/integrate-root-my-project-cmake

I had read this link, but obviously that link is for people who already know everything about CMake and compiling and linking… which was not my case, so that was all Greek to me :slight_smile: Luckily some copy-paste and a lot of trial and error finally did the trick anyway.

Thank you very much!

Check out how to setup QtCreator to build and debug ROOT scripts here: