Add a new include path to the macro

Hi experts

I want to add a directory in the include path and have already read the part of manual related to that. I still have some puzzle about that.
I have 2 dirs. One is include, one is macros. Under include, I have one header, the content is

namespace ana{
   const double PI = 3.14;
};

Under macros, I have one macros called test.C, the content is

void test(){
    gROOT->ProcessLine(".include ../include");
    gROOT->ProcessLine("#include \"consts.h\"");
    gROOT->ProcessLine("cout << ana::PI << endl;");
}

It works. But if I write like this

    gROOT->ProcessLine(".include ../include");
    gROOT->ProcessLine("#include \"consts.h\"");
    cout << ana::PI << endl;

or

#include "consts.h"
void test(){
    gROOT->ProcessLine(".include ../include");
    cout << ana::PI << endl;
}

It will not work.

And if I do in another way, in macros/test1.C,

#include "consts.h"
void test1(){
    cout << ana::PI << endl;
}

in macros/test2.C,

void test2(){
    gROOT->ProcessLine(".include ../include");
    gROOT->ProcessLine("#include \"consts.h\"");
    gROOT->ProcessLine(".x test1.C");
}

test2.C would work.

Is there any way to avoid using two macros to finish one task?

Thanks


ROOT Version: 6.18
Platform: MacOSX
Compiler: Not Provided


Try:

R__ADD_INCLUDE_PATH(../include)
#include "consts.h"
// ... the rest of your macro ...

In the first style, everything should be processed as string in gROOT. It seems I am working in prompt. Is there any way just let me work in a way like g++ I…/include

Thank you, Wile, it works and help me a lot!

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