Skip to content
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

Closed
springmeyer opened this issue Apr 30, 2014 · 15 comments
Closed

OS X compile error: call to 'abs' is ambiguous #1000

springmeyer opened this issue Apr 30, 2014 · 15 comments

Comments

@springmeyer
Copy link
Contributor

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 and libc++ should not be being linked because -DOSXLIBSTD="libstdc++" is being passed to cmake, but the configure output says:

-- Activating -std=c++11 flag for >= OS X 10.9
-- linking against libc++

Error is:

[ 22%] Building CXX object CMakeFiles/OSRM.dir/Algorithms/DouglasPeucker.cpp.o
/Users/travis/build/DennisOSRM/node-osrm/Project-OSRM/Algorithms/DouglasPeucker.cpp:102:37: 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.
make[2]: *** [CMakeFiles/OSRM.dir/Algorithms/DouglasPeucker.cpp.o] Error 1
@springmeyer
Copy link
Contributor Author

turns out this problem is occuring when building OSRM against homebrew installed deps:

brew install boost cmake protobuf libstxxl lua luabind osm-pbf

As such this is not a problem for me, since my primary approach is to build against static deps.

@DennisOSRM
Copy link
Collaborator

@springmeyer thx for the feedback.

@springmeyer
Copy link
Contributor Author

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....

@springmeyer
Copy link
Contributor Author

This works around the problem:

+ const double distance = std::abs((double)temp_dist);
- const double distance = std::abs(temp_dist);

@springmeyer
Copy link
Contributor Author

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;
}

@springmeyer springmeyer reopened this May 1, 2014
springmeyer pushed a commit to Project-OSRM/node-osrm that referenced this issue May 1, 2014
@springmeyer
Copy link
Contributor Author

I'll summarize:

  • This occurs with latest clang++ on OS X and is easy to replicate when building OSRM against libc++ in c++11 mode
  • There are numerous possible workarounds. I think the simplest is to use std::fabs

@DennisOSRM
Copy link
Collaborator

Thx. I'll Look into it.

@DennisOSRM
Copy link
Collaborator

Working on a fix

@DennisOSRM
Copy link
Collaborator

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.

DennisOSRM added a commit that referenced this issue May 2, 2014
DennisOSRM added a commit that referenced this issue May 7, 2014
@DennisOSRM
Copy link
Collaborator

@springmeyer is this still an issue?

@springmeyer
Copy link
Contributor Author

yes

@DennisOSRM
Copy link
Collaborator

yes=no? ;-)

@springmeyer
Copy link
Contributor Author

haha, sorry, yes this is fixed. no it is not still an issue :)

@DennisOSRM
Copy link
Collaborator

Cool. Thx

cbeck88 added a commit to wesnoth/wesnoth that referenced this issue Oct 27, 2014
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.
@entangledloops
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants