在 Mac OS Catalina 上,使用 clang-10 时出现 cmath 编译错误

在 Mac OS Catalina 上,使用 clang-10 时出现 cmath 编译错误

我最近在 Mac OS 10.15.4 Catalina 上通过 brew 安装了 llvm brew install llvm,以便将 clang 与 OpenMP 一起使用

$ which clang
/usr/local/opt/llvm/bin/clang
$ clang -v
clang version 10.0.0 
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

看来我cmath在编译 C++ 代码时遇到了基本错误,例如

/usr/local/opt/llvm/bin/../include/c++/v1/cmath:317:9: error: no member named
      'signbit' in the global namespace
using ::signbit;
      ~~^
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:318:9: error: no member named
      'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:319:9: error: no member named
      'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:749:12: note: 
      'finite' declared here
extern int finite(double)

这让我认为某些文件丢失了,也许是通过 Xcode?

任何想法如何解决这一问题?

答案1

我遇到了同样的问题,似乎 cmath 未能包含正确的 math.h。

应用此解决方案,我可以让编译工作正常,所以这样做:

vim /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath. 

#将'#include<math.h>'更改为

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

相关内容