Call to 'pow' is ambiguous

Hi, I’m having trouble compiling a surprisingly small function. I get the following error message about std::pow (which is the implementation of TMath::Power).

root [10] .L novosibirsk.C+
Info in <TUnixSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/virtual_garfield/./novosibirsk_C.so
In file included from /Users/jfcaron/Projects/Proto2BeamTest2/virtual_garfield/novosibirsk_C_ACLiC_dict.cxx:17:
In file included from /Users/jfcaron/Projects/Proto2BeamTest2/virtual_garfield/novosibirsk_C_ACLiC_dict.h:34:
In file included from /Users/jfcaron/Projects/Proto2BeamTest2/virtual_garfield/./novosibirsk.C:1:
/opt/local/include/root/TMath.h:503:13: error: call to 'pow' is ambiguous
   { return std::pow(x,y); }
            ^~~~~~~~
/usr/include/architecture/i386/math.h:343:15: note: candidate function
extern double pow ( double, double );
              ^
/usr/include/c++/4.2.1/cmath:356:3: note: candidate function
  pow(float __x, float __y)
  ^
/usr/include/c++/4.2.1/cmath:360:3: note: candidate function
  pow(long double __x, long double __y)
  ^
/usr/include/c++/4.2.1/cmath:364:3: note: candidate function
  pow(double __x, int __i)
  ^
/usr/include/c++/4.2.1/cmath:368:3: note: candidate function
  pow(float __x, int __n)
  ^
/usr/include/c++/4.2.1/cmath:372:3: note: candidate function
  pow(long double __x, int __n)
  ^
1 error generated.
clang: error: no such file or directory: '/Users/jfcaron/Projects/Proto2BeamTest2/virtual_garfield/novosibirsk_C_ACLiC_dict.o'
Error in <ACLiC>: Compilation failed!

Some stackoverflow people suggested using static_cast to specify the type of the first argument to pow, so I tried adding static_cast<Double_t> to the first arguments of TMath::Power, but the error remains.

The code can be .L’ed fine when I don’t wish to compile it. I’m using ROOT 5.34/15 from MacPorts, compiled using clang 3.2.

Thanks for any assistance in getting this to compile.
Jean-François
novosibirsk.C (754 Bytes)

New information: if I remove the TMath::Power calls and instead just multiply the first argument by itself (because both calls are just for powers of 2), I still get the same error message!

So this means that the ambiguous use of std::pow is not coming from TMath::Power. The lines in TMath.h that are using std::pow are quoted here (lines ~503):

inline LongDouble_t TMath::Power(Long64_t x, Long64_t y)
#if __cplusplus >= 201103 /*C++11*/
   { return std::pow(x,y); } // <---- This is line 503 with the error.
#else
   { return std::pow((LongDouble_t)x,(LongDouble_t)y); }
#endif

But why is this giving an error if I’ve commented out my uses of TMath::Power?

Jean-François

I am having the same issue as the above. Would appreciate any further information.

I ended up resolving the problem by upgrading my Mac OS to 10.9.

Previously I had only 10.7, and I installed the +clang variant of the ROOT port from MacPorts. I also had a command in my rootlogon.C file that would add the appropriate compiler flags when using “+” to compile things in order to get C++11 language support. I emphasise the language because it would still use the old libstdcxx runtime, so I wouldn’t get C++11 library support. I could use features like auto and range-based for loops, but not things like list-initialized vectors.

The problem with the call to ‘pow’ is that in the TMath.h file, it explicitly checks whether C++11 support is enabled, but I’m guessing it needs both C++11 language and library support.

Mac OS 10.9 uses a C++11-compatible runtime libc++, and the ROOT port automatically uses clang, so under 10.9 the error went away completely. Removing the C++11-language-enabling commands from my rootlogon.C would also have fixed it, but I had a few other reasons to upgrade.

At least that’s my understanding of the problem.

Jean-François

I met the same error. I solved it by simply including header file:
#include <cmath>

My Mac OS is High Sierra 10.15.5 and my Xcode is Version 9.4.1 (9F2000)