macOS 上的 Clang - 将 isysroot 设置为默认位置

问题描述 投票:0回答:1

我有一台运行 macOS Catalina (10.15.3) 和 XCode 版本 11.4.1 的 MacBook Pro 16。我正在尝试编译一些 C++ 文件,其中一个文件具有标题

math
,因为它正在使用一些数学函数。 每当我尝试使用
#include<math>
编译文件时,都会出现很多错误。编译是通过
clang++
完成的,可以在这里找到:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

编译错误:

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;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/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:7: error: no member named
      'isgreater' in the global namespace; did you mean '::std::greater'?
using ::isgreater;
      ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:731:29: note:
      '::std::greater' declared here
struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
                            ^
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:324:7: error: no member named
      'isgreaterequal' in the global namespace; did you mean '::std::greater_equal'?
using ::isgreaterequal;
      ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:760:29: note:
      '::std::greater_equal' declared here
struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
                            ^
In file included from main.cpp:2:
/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;
      ~~^
main.cpp:8:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto result = log(10.2);
    ^
main.cpp:9:9: error: no member named '__builtin_isless' in namespace 'std'; did you mean simply '__builtin_isless'?
    if (std::isless(result, 2))
        ^~~~~
main.cpp:9:14: note: '__builtin_isless' declared here
    if (std::isless(result, 2))
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/math.h:545:22: note:
      expanded from macro 'isless'
#define isless(x, y) __builtin_isless((x),(y))
                     ^
1 warning and 14 errors generated.

幸运的是,经过一些研究,我发现解决方案是使用带有附加标志的 clang++ 编译器:

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

这似乎解决了问题:我的源代码编译没有任何问题,我可以运行可执行文件。

但是,我不想每次必须编译一些东西时都通过它。

问: 有没有办法让

isysroot
始终指向该 SDK 位置?

我知道我可以创建一个

clang++
的别名,在其中我可以传递额外的标志,但我想知道是否还有其他方法。

提前谢谢您!

c++ macos zsh macos-catalina
1个回答
0
投票

我在自定义 clang 构建中偶然发现了类似的问题。事实证明,cmake 默认情况下传递 isysroot 选项(至少在较新的版本中)。所以你的问题的答案可能是:使用 cmake 构建项目。

© www.soinside.com 2019 - 2024. All rights reserved.