Question about local .h and .C files

Hi, this is a pretty basic question but I could not find existing posts about it.

I had my code in a big analysis.C file which I ran as a named macro using:

In the file I had my main function called “analysis” and several other functions.

I want to move the other functions now to an external file so that I can #include/.L them separately from the main “analysis” function. I took all the function declarations and put them in algorithms.h and the definitions in algorithms.C (along with proper #includes).

From CINT I can .L algorithms.C+ and see the functions and use them. But now I am unsure how to make analysis.C know about the algorithms file. I put #include “algorithms.h” but it does not like it, I also tried putting gROOT->LoadMacro(“algorithms.C+”) in the body of the analysis function, but always it says “not defined in current scope”.

What is the proper way to include personal .h and .C files into another ROOT named macro? I thought it would be straightforward, but apparently I am missing something.

Thanks,
Jean-François

The specific error message I get is as follows. In my description above I called my macro just “analysis” but it is really called “standard_analysis” and my algorithms file is called CC_algorithms.h/.C.

[code]root -b -q -l ‘standard_analysis.C+("…/rootfiles/Outputs/Run0535","./out",“iif”,9200,100,0.00035)’

  • ROOT v5.34/03 *

root [0]
Processing standard_analysis.C+("…/rootfiles/Outputs/Run0535","./out",“iif”,9200,100,0.00035)…
Info in TUnixSystem::ACLiC: creating shared library /Users/jfcaron/Projects/TRIUMFBeamTest/standard_analysis/./standard_analysis_C.so
Undefined symbols for architecture x86_64:
“get_runnum(TString)”, referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"smoothed_tv(TVectorT const&, int)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"Cellwise_Separation(std::vector<int, std::allocator > const&)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"Combine_Separations(double, int, double, int)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"clu_second_derivative(TVectorT const&, int, float, int)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"get_inverted_channels(int)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
"get_scintilator_distance(int)", referenced from:
standard_analysis(char*, char*, char*, …) in standard_analysis_C_ACLiC_dict.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in : Compilation failed!
Error: Function standard_analysis("…/rootfiles/Outputs/Run0535","./out",“iif”,9200,100,0.00035) is not defined in current scope :0:
*** Interpreter error recovered ***
[/code]

I think I found a solution, shortly after posting my question. Perhaps people can still suggest improvements or provide explanations.

I removed the algorithms.h file entirely and kept the function declarations in the algorithms.C file. Then in my main analysis.C named macro, I do #include “algorithms.C”. It works now.

Jean-François