卡塔琳娜C ++:使用< cmath>标头产生错误:全局名称空间中没有名为"signbit"的成员 [英] Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace

查看:511
本文介绍了卡塔琳娜C ++:使用< cmath>标头产生错误:全局名称空间中没有名为"signbit"的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Mojave升级到Catalina后,在环境中设置:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk.

After upgrading to Catalina from Mojave, Setuping: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk in the env.

我无法编译使用<cmath>标头的程序.

I'm unable to compile a program that use <cmath> header.

我尝试更改CFLAGS,CCFLAGS,CXXFLAGS以指向不变的MacOSSDK位置

I tried changing CFLAGS, CCFLAGS, CXXFLAGS to point to the MacOSSDK Location that change nothing

Scanning dependencies of target OgreMain
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f OgreMain/CMakeFiles/OgreMain.dir/build.make OgreMain/CMakeFiles/OgreMain.dir/build
[  0%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreASTCCodec.cpp.o
cd /Users/roman/Downloads/ogre-1.12.2/build/OgreMain && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -DOgreMain_EXPORTS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OSX -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/include/Threading -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/src -I/Users/roman/Downloads/ogre-1.12.2/build/Dependencies/include -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/include -I/Users/roman/Downloads/ogre-1.12.2/build/include -I/Users/roman/Downloads/ogre-1.12.2/OgreMain -isystem /usr/local/include  -Wall -Winit-self -Wcast-qual -Wwrite-strings -Wextra -Wundef -Wmissing-declarations -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long -Wno-inconsistent-missing-override  -msse -O3 -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fPIC -fvisibility=hidden -fvisibility-inlines-hidden   -std=c++11 -o CMakeFiles/OgreMain.dir/src/OgreASTCCodec.cpp.o -c /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreASTCCodec.cpp
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreASTCCodec.cpp:29:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreStableHeaders.h:40:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/include/OgrePrerequisites.h:309:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/include/OgreStdHeaders.h:10:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:314: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:315: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:316:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;

例如,宏:isless存在于全局名称空间和我的计算机上:

for example the macro: isless is present in the global namespace and on my computer:

➜ cat math.h | grep "isless"

#define isless(x, y) __builtin_isless((x),(y))
#define islessequal(x, y) __builtin_islessequal((x),(y))
#define islessgreater(x, y) __builtin_islessgreater((x),(y))
➜  pwd
/usr/local/include
➜

即使cmath标头包含它:

Even the cmath header include it:

➜ cat /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath | grep "math.h"
#include <math.h>

我的命令行具有选项-isystem /usr/local/include

这应该有效...

推荐答案

我很好奇:您使用的是什么编译器? CMAKE_OSX_SYSROOT的值是什么?

I'm curious: What compiler are you using? What's the value of CMAKE_OSX_SYSROOT?

我相当确信这是错误的CMAKE_OSX_SYSROOT的结果.我在使用python绑定进行clang时遇到了您要描述的问题(其中CMake不管理编译器调用),但是我设法通过以下操作在CMake中重新创建了错误:

I'm fairly convinced this is the result of a wrong CMAKE_OSX_SYSROOT. I had the problem you're describing when using python bindings for clang (where CMake doesn't manage the compiler call), but I managed to recreate the error in CMake by doing:

set(CMAKE_OSX_SYSROOT "")  # Reset.

我通过遵循以下问题的答案解决了我的问题:

I solved my problem by following the answers to this question: Cannot compile R packages with c++ code after updating to macOS Catalina.

总结:在Catalina上,/usr/include已被SIP清除并受其保护.因此,任何期望在那里找到C头的项目都将无法编译.如果我没记错的话,Apple建议将错误报告归档到需要/usr/include中带有C标头的项目.

To summarise: On Catalina, /usr/include is purged and protected by SIP. Thus, any project that expects the C headers to be found there will fail to compile. If I remember correctly, Apple recommends to file bug reports to projects that expect C headers in /usr/include.

您必须将要编译的代码的构建系统指向正确的标题:

You must point the build system of the code you're trying to compile to the right headers:

(1)确保Xcode是最新的.没有人说过Catalina上过时的Xcode可能会对您的构建环境产生什么影响.

(1) Make sure Xcode is up to date. There's no telling what an outdated Xcode on Catalina might do to your build environment.

(2)使用-isysroot /sdk/path编译器标志,其中/sdk/pathxcrun --show-sdk-path的结果.我不确定CMake的最佳做法是什么,但是请尝试

(2) Use the -isysroot /sdk/path compiler flag, where /sdk/path is the result of xcrun --show-sdk-path. I'm not sure what CMake's best practice is, but try doing

set(CMAKE_OSX_SYSROOT /sdk/path)

set(CMAKE_CXX_FLAGS "[...] -isysroot /sdk/path")

如果这可以解决问题,则可能需要寻找一种更好的方法来在CMake中完成此操作.

If that solves the problem, you may want to look for a better way to do this in CMake.

当然,如果您喜欢冒险,也可以按照我的问题的答案中的建议禁用SIP:

Of course, if you're adventurous, you could also disable SIP, as suggested in the answer to my question: /usr/include missing on macOS Catalina (with Xcode 11)

这篇关于卡塔琳娜C ++:使用&lt; cmath&gt;标头产生错误:全局名称空间中没有名为"signbit"的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆