我有一个运行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.
幸运的是,在some research之后,我发现一种解决方案是使用带有附加标志的clang ++编译器:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
这似乎可以解决问题:我的源代码编译时没有任何问题,我可以运行可执行文件。
但是,我不想每次都要编译某些东西时都通过。
问:有没有办法使该isysroot
始终指向该SDK位置?
我知道我可以为clang++
创建一个别名,在其中可以传递多余的标志,但是我想知道是否还有另一种方法。
提前谢谢!