Error in Adding TGraph. h to cpp file

Good morning,

Please, I have a cmake folder that I have built and installed. I included root in my CMAKELISTS.txt. After building my folder, I had an error with the make -j4. I think that the error relates to me adding TGraph.h to my main.cpp file because if I remove TGraph.h, I do not get the error. This is the error I get:

‘’’
harriet@harriet-ROG-Zephyrus-G15-GA503RM-GA503RM:~/kalman filter/OpenKF/build$ make -j4
[ 14%] Built target OpenKF
[ 28%] Built target example__kf_state_estimation
[ 42%] Built target example__unscented_transform
[ 57%] Built target example__ekf_range_sensor
[ 64%] Building CXX object Examples/ukf_range_sensor/CMakeFiles/example__ukf_range_sensor.dir/main.cpp.o
[ 92%] Built target example__test_least_squares
[ 92%] Built target example__sr_ukf_linear_function
In file included from /home/harriet/root/root-6.28.04/root-install/include/ROOT/RConfig.hxx:23,
from /home/harriet/root/root-6.28.04/root-install/include/RtypesCore.h:23,
from /home/harriet/root/root-6.28.04/root-install/include/TMathBase.h:29,
from /home/harriet/root/root-6.28.04/root-install/include/TMath.h:15,
from /home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:16:
/home/harriet/root/root-6.28.04/root-install/include/RConfigure.h:30:4: warning: #warning “The C++ standard in this build does not match ROOT configuration (201703L); this might cause unexpected issues” [-Wcpp]
30 | # warning “The C++ standard in this build does not match ROOT configuration (201703L); this might cause unexpected issues”
| ^~~~~~~
In file included from /home/harriet/root/root-6.28.04/root-install/include/TString.h:29,
from /home/harriet/root/root-6.28.04/root-install/include/TNamed.h:26,
from /home/harriet/root/root-6.28.04/root-install/include/TGraph.h:24,
from /home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:22:
/home/harriet/root/root-6.28.04/root-install/include/ROOT/RStringView.hxx:90:17: error: expected type-specifier
90 | operator std::string_view() const { return std::string_view(fData,fLength); }
| ^~~
In file included from /home/harriet/root/root-6.28.04/root-install/include/TNamed.h:26,
from /home/harriet/root/root-6.28.04/root-install/include/TGraph.h:24,
from /home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:22:
/home/harriet/root/root-6.28.04/root-install/include/TString.h:118:13: error: expected type-specifier
118 | operator std::string_view() const { return std::string_view(Data(),fExtent); }
| ^~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:291:32: error: ‘string_view’ in namespace ‘std’ does not name a type
291 | explicit TString(const std::string_view &sub);
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:291:27: note: ‘std::string_view’ is only available from C++17 onwards
291 | explicit TString(const std::string_view &sub);
| ^~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:328:37: error: ‘string_view’ in namespace ‘std’ does not name a type
328 | TString &operator=(const std::string_view &s);
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:328:32: note: ‘std::string_view’ is only available from C++17 onwards
328 | TString &operator=(const std::string_view &s);
| ^~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:456:9: error: ‘string_view’ in namespace ‘std’ does not name a type
456 | std::string_view View() const { return std::string_view(GetPointer(),Length()); }
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:456:4: note: ‘std::string_view’ is only available from C++17 onwards
456 | std::string_view View() const { return std::string_view(GetPointer(),Length()); }
| ^~~
In file included from /home/harriet/root/root-6.28.04/root-install/include/TNamed.h:26,
from /home/harriet/root/root-6.28.04/root-install/include/TGraph.h:24,
from /home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:22:
/home/harriet/root/root-6.28.04/root-install/include/TString.h:851:53: error: ‘string_view’ in namespace ‘std’ does not name a type
851 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:851:48: note: ‘std::string_view’ is only available from C++17 onwards
851 | inline Bool_t operator==(const char s1, const std::string_view &s2)
| ^~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:851:15: error: ‘Bool_t operator==(const char
, const int&)’ must have an argument of class or enumerated type
851 | inline Bool_t operator==(const char s1, const std::string_view &s2)
| ^~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:856:37: error: ‘string_view’ in namespace ‘std’ does not name a type
856 | inline Bool_t operator==(const std::string_view &s1, const char s2)
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:856:32: note: ‘std::string_view’ is only available from C++17 onwards
856 | inline Bool_t operator==(const std::string_view &s1, const char s2)
| ^~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:856:15: error: ‘Bool_t operator==(const int&, const char
)’ must have an argument of class or enumerated type
856 | inline Bool_t operator==(const std::string_view &s1, const char s2)
| ^~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:869:37: error: ‘string_view’ in namespace ‘std’ does not name a type
869 | std::string printValue(const std::string_view
val);
| ^~~~~~~~~~~
/home/harriet/root/root-6.28.04/root-install/include/TString.h:869:32: note: ‘std::string_view’ is only available from C++17 onwards
869 | std::string printValue(const std::string_view
val);
| ^~~
/home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp: In function ‘void energyloss(std::string, TGraph
)’:
/home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:60:20: error: aggregate ‘std::ifstream elossfile’ has incomplete type and cannot be defined
60 | std::ifstream elossfile;
| ^~~~~~~~~
/home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:68:40: error: ‘ios’ has not been declared
68 | elossfile.open(eLossFileName_,ios::in);
| ^~~
/home/harriet/kalman filter/OpenKF/Examples/ukf_range_sensor/main.cpp:69:50: error: ‘std::ifstream::traits_type’ has not been declared
69 | if ((elossfile.peek() == std::ifstream::traits_type::eof())) {
| ^~~~~~~~~~~
make[2]: *** [Examples/ukf_range_sensor/CMakeFiles/example__ukf_range_sensor.dir/build.make:76: Examples/ukf_range_sensor/CMakeFiles/example__ukf_range_sensor.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:325: Examples/ukf_range_sensor/CMakeFiles/example__ukf_range_sensor.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

‘’’

these are my:
_ROOT Version: root_v6.28.04.source.tar.gz

_Platform:Ubuntu 22.04.3 LTS
_Compiler: c++

Hi,

It seems to me that your are building with a too low C++ version. ROOT now requires C+±17, see this message you are having:

# warning “The C++ standard in this build does not match ROOT configuration (201703L); this might cause unexpected issues”

You should add in your CMake file the requirement to have C+±17, by adding for example this line:

set(CMAKE_CXX_STANDARD 17 CACHE STRING "")

Lorenzo

Thank you very much it worked.