# Setting up an IDE for ROOT

**URL:** <https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875>\
**Category:** Newbie\
**Created:** [September 4, 2019, 12:54pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875 "2019-09-04T12:54:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 4, 2019, 12:54pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/1 "2019-09-04T12:54:55Z")

</div>

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](https://root-forum.cern.ch/t/ide-for-root/22418/4) 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:

```auto
#include <TF1.h>

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

```

This generates the following error in the parser

```nohighlight
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:

```nohighlight
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!

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 5, 2019, 11:09am UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/2 "2019-09-05T11:09:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [September 5, 2019, 11:45am UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/3 "2019-09-05T11:45:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 5, 2019, 12:08pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/4 "2019-09-05T12:08:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [September 5, 2019, 2:08pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/5 "2019-09-05T14:08:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 5, 2019, 2:50pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/6 "2019-09-05T14:50:53Z")

</div>

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

```nohighlight
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

```auto
#include <TH1.h>

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

```

I get

```auto
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

```nohighlight
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

```auto
TF1* func = new TF1()

```

in interactive mode doesn’t throw any error.

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 5, 2019, 4:07pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/7 "2019-09-05T16:07:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 9, 2019, 6:19am UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/8 "2019-09-09T06:19:32Z")

</div>

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 🙂

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](https://root.cern.ch/how/integrate-root-my-project-cmake)

---

<div class="post-metadata">

**Author:** ![renyhp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@renyhp](https://root-forum.cern.ch/u/renyhp)\
**Post date:** [September 9, 2019, 8:18am UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/9 "2019-09-09T08:18:19Z")

</div>

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](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 🙂 Luckily some copy-paste and **a lot** of trial and error finally did the trick anyway.

Thank you very much!

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 3, 2022, 6:56pm UTC](https://root-forum.cern.ch/t/setting-up-an-ide-for-root/35875/10 "2022-03-03T18:56:54Z")

</div>

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

> **[Coding in ROOT with the horsepower of an F1](https://root.cern/blog/code-horsepower-f1/)**
>
> If you’ve ever rubbed your eyes trying to decrypt C++ compilation errors from a terminal, traced those back to the line in the ROOT script you were just typing in your plain text editor, then googled CERN ROOT TTree to fix the signature of that...
