Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang++ doesn't compile cmath in macOS Catalina

I have a simple C++ program that imports cmath.

#include <cmath>

int main() {
    return 0;
}

I'm trying to compile it using the following command.

clang++ -o test main.cpp -std=c++14

But, I get the following errors

In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: 
      no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318:9: error: 
      no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:319:9: error: 
      no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/usr/local/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
           ^
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:320:9: error: 
      no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:321:9: error: 
      no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:322:9: error: 
      no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:323:9: error: 
      no member named 'isgreater' in the global namespace
using ::isgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:324:9: error: 
      no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:325:9: error: 
      no member named 'isless' in the global namespace
using ::isless;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:326:9: error: 
      no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:327:9: error: 
      no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:328:9: error: 
      no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:329:9: error: 
      no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:335:9: error: 
      no member named 'abs' in the global namespace; did you mean 'fabs'?
using ::abs;
      ~~^
/usr/local/include/math.h:417:15: note: 'fabs' declared here
extern double fabs(double);
              ^
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:26: error: 
      no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:60: error: 
      no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:18: error: 
      no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:50: error: 
      no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                                                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:646:17: error: 
      no template named 'numeric_limits'
  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Here are my system specifications.

macOS Catalina Version 10.15.2

Apple clang version 11.0.3 (clang-1103.0.32.29)

Xcode Version 11.4 (11E146) (not sure if this matters)

Thanks for any assistance!

EDIT: Updated to macOS 10.15.4 and Xcode 11.4.1 and still have the same issue

like image 865
Carpetfizz Avatar asked Apr 15 '20 19:04

Carpetfizz


1 Answers

I believe this is answered at Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace

The easiest solution seems to be to uninstall the Command Line Tools, which works on Catalina, but I was hitting this on High Sierra, where I resorted to editing /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath

to comment out #include <math.h> and replace it with:

#include</Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h>

I had to do this to get homebrew's Rust (rustc-1.53.0) to compile on High Sierra. Probably a better approach would be to tell cmake:

set(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk)

since it's not usually a great idea to mess with the system-supplied headers.

like image 170
Some Guy on the Internet Avatar answered Nov 06 '22 01:11

Some Guy on the Internet