osrm-backend: OS X compile error: call to 'abs' is ambiguous

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

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

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