ACLiC problem

Hello. I like the way how ROOT(CINT) uses compiler to compile code, instead of interpreting, so, I use this mode for small programs, which use ROOT. But , I got unexpected problem today. That’s the minimum, required to reporoduce the problem (test.C):

class My{};

double distance(const My &, const My &)
{
    return 0;
}

void test()
{
    My m, n;
    distance(m, n);
}

And in ROOT I do:

.L test.C++.

It’s clear, that such a program should at least compile ok (you can test it with g++ -c test.C).
But with ROOT I have:

It’s clear, that due to some ROOT’s machinery, .L test.C++ is not the same as compiling standalone C++ program and std::distance was somehow found and this breaks compilation, though nobody asked.

[quote]It’s clear, that due to some ROOT’s machinery, .L test.C++ is not the same as compiling standalone C++ program and std::distance was somehow found and this breaks compilation, though nobody asked.[/quote]When ACLiC compiles your code, it generates a dictionary and this dictionary does explicitly includes several required ROOT header files including one that requires #include which introduces the distance template. This dependency would be hard to remove. (It is compounded to the fact that because of a limitation of CINT, the dictionary also contains the statement ‘using namespace std;’)

To work around this issue simply rename ‘distance’ either by changing its name or by putting into a separate namespace.

Cheers,
Philippe.

[quote=“pcanal”][quote]
To work around this issue simply rename ‘distance’ either by changing its name or by putting into a separate namespace.

Cheers,
Philippe.[/quote][/quote]

Hello Philippe. Yes, sure, I know how to fix it :slight_smile: I suspected, that there are some headers included implicitly and using namespace std; somewhere is introduced (BTW, congratulations to all people, who do this in header files, I have to work with such a code very often :slight_smile: )

Thanks.

[quote]using namespace std; somewhere is introduced (BTW, congratulations to all people, who do this in header files, I have to work with such a code very often )[/quote]In this case, it is introduced by the dictionary itself because there is no way around it (because of the CINT limitations which lead to ‘std’ often not being set when it should in the database that is used to produce the dictionary).

Philippe.

Yes, that’s ok and I understand why you need this and I can work around these limitations.
In general, the problem is more serious - using namespace std + std::distance’s return type + the way how C++ compiler works.

Thanks for your help, Philippe!