I have a macro that runs smoothly and produces all the desired results when I run it using:
.x macro.cpp
But when I try to compile it using:
.L macro.cpp+
it complains about almost everything ! It does not recognize TCanvas, TTree etc. There are so many errors that I need to attach the error report as a text file.error.txt (4.02 KB)
#include<vector>
TGraphErrors* header(TString filen1)
{
std::vector< std::vector<double> > vec;
// a lot of things.... where we fill the vector "vec"
TGraphErrors *g = new TGraphErrors(vec[0].size(), &vec[0][0], &vec[1][0], &vec[2][0], &vec[3][0]);;
return g;
}
Suppose that my c++ syntax is fine, how can I avoid those “TBlahBlah” doesn’t name a type errors ?
Thanks a lot, that eliminated all the errors except this one:
/home/.../macros/macro_cpp_ACLiC_dict.o: In function `macro()':
macro_cpp_ACLiC_dict.cxx:(.text+0xdd2): undefined reference to `header1(TString)'
collect2: error: ld returned 1 exit status
Error in <ACLiC>: Compilation failed!
I checked and rechecked, there’s no problem with the definition/declaration of the function (header1(TString)) in header1.cpp and header1.h, no spelling or type of data issues… and it’s obvious because my code works smoothly if I don’t try to compile and just execute using .x macro.cpp.
That was a typo, header1 or header it’s the same, it’s a fake name I am using just for this post. I have two files: header1.cpp containing the full definition and header1.h containing just the declaration. I have included header1.cpp and the macro.cpp both contain the header1.h file.
The next part of your answer solved the problem, I had to compile all source files in order of their occurrences. I have a mixed feeling about this, If a program is complicated and long, I have to first list down all the headers in order of their occurrences and compile in that order, which is a bit annoying ! Is there a way around this ?
By the way can anyone please help me with the next step, so after compiling all my source files:
You could write a Makefile, to compile all your sources into a single library. Then in ROOT you just load that library. See for instance test/Makefile and its EVENTSO.