New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS X compile error: call to 'abs' is ambiguous #1000
Comments
turns out this problem is occuring when building OSRM against homebrew installed deps:
As such this is not a problem for me, since my primary approach is to build against static deps. |
@springmeyer thx for the feedback. |
was able to replicate. Going to keep closed until this is actionable, but log some notes here as I find details about what is going on.... |
This works around the problem: + const double distance = std::abs((double)temp_dist);
- const double distance = std::abs(temp_dist); |
re-opening, this looks to me like a libc++/c++11 bug, but will need a workaround in OSRM. Here is a reduced testcase: #include <cmath>
/*
Workaround by including this header:
#include <cstdlib>
Or workaround by doing:
const double distance = std::abs((double)temp_dist);
Or by doing:
const double distance = std::fabs(temp_dist);
*/
/*
clang++ -o abs abs.cpp
abs.cpp:17:29: error: call to 'abs' is ambiguous
const double distance = std::abs(temp_dist);
^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cmath:660:1: note: candidate function
abs(float __x) _NOEXCEPT {return fabsf(__x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cmath:664:1: note: candidate function
abs(double __x) _NOEXCEPT {return fabs(__x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cmath:668:1: note: candidate function
abs(long double __x) _NOEXCEPT {return fabsl(__x);}
^
1 error generated.
$ clang++ -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
*/
int main() {
const int temp_dist = -1;
const double distance = std::fabs(temp_dist);
return 0;
} |
I'll summarize:
|
Thx. I'll Look into it. |
Working on a fix |
Fix will be pushed in a couple of minutes once tests have passed locally. The reason was simple and somewhat dull. The variable temp_dist should not have been int after all but a double. |
@springmeyer is this still an issue? |
yes |
yes=no? ;-) |
haha, sorry, yes this is fixed. no it is not still an issue :) |
Cool. Thx |
Ancestral reported compilation errors with clang on OS X, basically similar to what is reported here: Project-OSRM/osrm-backend#1000 I fix it by replacing calls to std::abs, with calls to _abs, a function pointer I define to be & _abs, so that I can control exactly which overload is selected and thus resolve the ambiguity.
Headsup: the fabs solution works for clang, but doesn't work with at least Visual Studio 2013 (which will now report ambiguous call for fabs). |
This is happening on Travis's OS X machines. Full log is here. Details on XCode for this machine is here.
One odd thing is that
c++11
should not be enabled andlibc++
should not be being linked because-DOSXLIBSTD="libstdc++"
is being passed to cmake, but the configure output says:Error is:
The text was updated successfully, but these errors were encountered: