Hello!I want to know how to run root on jetbrains clion?

I have a project named ROOTTest and the project has a cpp file named main.cpp.

here are some environment variables:
ROOT_SYS: /opt/root
ROOT_INCLUDE_DIRS: /opt/root/include
ROOT_LIBRARIES: /opt/root/lib

i edit CMakeLists in CLion like this:

cmake_minimum_required(VERSION 3.6)#原始
project(ROOTTest)#原始

set(CMAKE_CXX_STANDARD 11)#原始


list(APPEND CMAKE_PREFIX_PATH  $ENV{ROOTSYS})  
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $ENV{ROOT_SYS}/etc/cmake)
find_package(ROOT REQUIRED COMPONENTS RIO Net)
include_directories($ENV{ROOT_INCLUDE_DIRS})
link_directories(/opt/builddir/lib)


set(SOURCE_FILES main.cpp)#原始

add_executable(ROOTTest ${SOURCE_FILES})#原始
target_link_libraries(ROOTTest -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
)

main.cpp is like this:

#include <iostream>
#include <stdlib.h>
#include "TTree.h"
#include "TROOT.h"
#include "TRandom.h"
#include "TFile.h"
#include "TLeaf.h"
#include "TMessage.h"
#include "TBrowser.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include "TBuffer.h"



using namespace std;

int main(){
    new TBrowser();
    return 0;
}

but the result is like this:

/home/mrw/Files/各种学习/各种毕业设计/各种测试/ROOTTest/cmake-build-debug/ROOTTest

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f9a6e5a44ca in __GI___waitpid (pid=18271, stat_loc=stat_loc
entry=0x7ffd38cda180, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f9a6e51dfbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f9a6f5ac274 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x223a4f0) at /opt/root/core/unix/src/TUnixSystem.cxx:2073
#3  TUnixSystem::StackTrace (this=0x223a4f0) at /opt/root/core/unix/src/TUnixSystem.cxx:2301
#4  0x00007f9a6f5ae35c in TUnixSystem::DispatchSignals (this=0x223a4f0, sig=kSigSegmentationViolation) at /opt/root/core/unix/src/TUnixSystem.cxx:3539
#5  <signal handler called>
#6  0x0000000000400c34 in hello () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/ROOTTest/main.cpp:39
#7  0x0000000000400d24 in main () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/ROOTTest/main.cpp:53
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x0000000000400c34 in hello () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/ROOTTest/main.cpp:39
#7  0x0000000000400d24 in main () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/ROOTTest/main.cpp:53
===========================================================

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

why the program can’t run?

Hi,

The code you posted (only main()) doesn’t correspond to the crash (main() calls hello()). And as the crash happens in hello() you’ve skipped the relevant part.

Axel.

Hello!The error is like this. I just can’t use TBrowser in main function. The other functions are OK

/home/mrw/Files/各种学习/各种毕业设计/各种测试/MyROOTTest/cmake-build-debug/MyROOTTest

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f1eead184ca in __GI___waitpid (pid=5643, stat_loc=stat_loc
entry=0x7ffe0468f8c0, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f1eeac91fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f1eeb87b274 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x1e964f0) at /opt/root/core/unix/src/TUnixSystem.cxx:2073
#3  TUnixSystem::StackTrace (this=0x1e964f0) at /opt/root/core/unix/src/TUnixSystem.cxx:2301
#4  0x00007f1eeb87d35c in TUnixSystem::DispatchSignals (this=0x1e964f0, sig=kSigSegmentationViolation) at /opt/root/core/unix/src/TUnixSystem.cxx:3539
#5  <signal handler called>
#6  TApplication::InitializeGraphics (this=0x0) at /opt/root/core/base/src/TApplication.cxx:273
#7  0x00007f1eeb7871dd in TBrowser::TBrowser (this=0x1ececc0, name=0x400d4d "Browser", title=0x400d39 "ROOT Object Browser", extimp=0x0, opt=0x400d38 "") at /opt/root/core/base/src/TBrowser.cxx:97
#8  0x0000000000400b67 in main () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/MyROOTTest/main.cpp:19
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  TApplication::InitializeGraphics (this=0x0) at /opt/root/core/base/src/TApplication.cxx:273
#7  0x00007f1eeb7871dd in TBrowser::TBrowser (this=0x1ececc0, name=0x400d4d "Browser", title=0x400d39 "ROOT Object Browser", extimp=0x0, opt=0x400d38 "") at /opt/root/core/base/src/TBrowser.cxx:97
#8  0x0000000000400b67 in main () at /home/mrw/Files/各种学习/各种毕业设计/各种测试/MyROOTTest/main.cpp:19
===========================================================



Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I change the main function like this:

int main() {
    
    TApplication *a = new TApplication("a", 0, 0);
    TBrowser tBrowser;

    return 0;
}

But it only appeared for few seconds and then disappeard.

Questions like these are why we recommend not to build your own program, but use your code from inside ROOT.

Do you really need to build your own program?

(The reason is that you don’t create an event loop; TApplication::Run() does that.)

Axel.

1 Like

Thank you very much! The problem is solved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.