How to use root library in c++ projections?

I want to build a c++ projection using root library, the code below:

#include <iostream>

#include <TApplication.h>

int main()
{
    std::cout<<"hello world!"<<std::endl;
    return 100000000;
}

when compiling the projection, the error occurs:

home/llh/root/TGeometry/SimpleFissionChamber/SFC.C:4:10: fatal error: TApplication.h: 没有那个文件或目录
    4 | #include <TApplication.h>
      |          ^~~~~~~~~~~~~~~~
compilation terminated.

anything else i shauld do to use root library?


Please read tips for efficient and successful posting and posting code_

ROOT Version: 6.22/06
Platform: ubuntu 20.04
Compiler: GCC 9.3.0


What is exactly the fatal error you get ? file not found ?

yes, TApplication.h file can not be found,
i think: maybe the GCC can not compile the root code, but the root compiler can make c++ code.

is the variable ROOTSYS defined ?

yes,
root@llh-virtual-machine:~# echo $ROOTSYS
/usr/local/root/root
root@llh-virtual-machine:~#

Have you “sourced” the script thisroot.sh from the $ROOTSYS/bin/ directory ?

yes, my root program works well.
maybe the root configuration environment is wrong in CMakeLists.txt file,
when revised the CMakeLists.txt file, the code works well.

I am not sure what’s wrong then. May be @oshadura has an idea.

Can you please share your CMakeLists.txt file?
Here is an example of how to integrate ROOT in your CMake project: Integrating ROOT into CMake projects - ROOT

Yup, looks like a missing target_include_directories or similar in the CMakeLists.txt.

CMakeLists.txt (438 Bytes)
when i use this CMakeLists.txt file, everything works well.

thanks all!

1 Like

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