【问题标题】:C++: error: no member named 'signbit' in the global namespaceC++:错误:全局命名空间中没有名为“signbit”的成员
【发布时间】:2022-01-12 01:53:33
【问题描述】:

TL;DR: 尝试编译时#include <cmath> 标头会产生no member named 'signbit' in the global space

目标:编译一个纯 C++ gRPC 客户端-服务器应用程序

错误:

g++ -std=c++17 client.cpp mathtest.pb.cc mathtest.grpc.pb.cc -o  client `pkg-config --libs --cflags protobuf grpc++`
In file included from client.cpp:3:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpc++/grpc++.h:26:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/grpcpp.h:52:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/channel.h:28:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/completion_queue.h:45:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/sync.h:32:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/mutex.h:72:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/internal/kernel_timeout.h:34:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/clock.h:26:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/time.h:78:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:321:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:322:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:323:9: error: no member named 'isfinite' in the global namespace
using ::isfinite;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:324:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:325:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:326:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:327:7: error: no member named 'isgreater' in the global namespace; did you mean '::std::greater'?
using ::isgreater;
      ^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:742:29: note: '::std::greater' declared here
struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
                            ^
In file included from client.cpp:3:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpc++/grpc++.h:26:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/grpcpp.h:52:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/channel.h:28:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/completion_queue.h:45:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/sync.h:32:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/mutex.h:72:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/internal/kernel_timeout.h:34:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/clock.h:26:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/time.h:78:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:328:7: error: no member named 'isgreaterequal' in the global namespace; did you mean '::std::greater_equal'?
using ::isgreaterequal;
      ^~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:771:29: note: '::std::greater_equal' declared here
struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
                            ^
In file included from client.cpp:3:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpc++/grpc++.h:26:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/grpcpp.h:52:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/channel.h:28:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/completion_queue.h:45:
In file included from /opt/homebrew/Cellar/grpc/1.41.1/include/grpcpp/impl/codegen/sync.h:32:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/mutex.h:72:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/synchronization/internal/kernel_timeout.h:34:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/clock.h:26:
In file included from /opt/homebrew/Cellar/abseil/20210324.2_1/include/absl/time/time.h:78:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:329:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:330:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:331:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:332:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:333:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^

这只是其他正在发生的事情的一个小sn-p。 cmath 还有一些错误,但我认为一旦实施解决方案,大部分(如果不是全部)都会被清除。

我的尝试:

  • 使用不同的 SDK 路径
#Check the current sdk
xcrun --show-sdk-path

#Change sdk
sudo xcode-select -s /Library/Developer/CommandLineTools          #Using CommandLineTools SDK
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer   #Using XCode.app SDK
  • this post 中所述更改CMath 文件中的#include 链接。

修复:

  1. 如果我们可以先将#include<...>的搜索顺序改为搜索>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/inclu>de/c++/v1,可以修。

  2. 使用 #include/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h> 而不是 在 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath

  • 在我的编译命令中添加-isysroot /sdk/path 标志(下面的完整命令)

g++ -std=c++17 client.cpp mathtest.pb.cc mathtest.grpc.pb.cc -o client -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk 'pkg-config --libs --cflags protobuf grpc++'

  • 卸载、重新安装和更新 Xcode 命令行工具
  • 重新安装 gcc

配置:

                 ,xNMM.          ---------------------------------
               .OMMMMo           OS: macOS 12.0.1 21A559 arm64
               OMMM0,            Host: MacBookPro18,3
     .;loddo:' loolloddol;.      Kernel: 21.1.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 12 days, 22 hours, 41 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 53 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.8
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 1512x982
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Dark)
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: iTerm2
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   Terminal Font: Monaco 12
    kMMMMMMMMMMMMMMMMMMMMMMd     CPU: Apple M1 Pro
     ;KMMMMMMMWXXWMMMMMMMk.      GPU: Apple M1 Pro
       .cooc,.    .,coo:.        Memory: 3551MiB / 32768MiB

不完全确定我还能找到什么。从我所做的几个小时的研究来看,这似乎是 MacOS 问题,而不是配置/设置问题。任何帮助将不胜感激。

【问题讨论】:

标签: c++ visual-studio-code grpc cmath


【解决方案1】:

经过一番挖掘,我发现最有可能出错的地方......

我在终端中执行了gcc -Wp,-v -E -,以查看正在以什么顺序搜索哪些路径。

这是输出:

#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

如您所见,首先搜索的是 /usr/local/include,它确实包含一个版本的“math.h”。

确定这一点后,我编辑了“cmath”中的#include 行,使其直接指向同一目录中的行,如下所述:

// this was here before
#include <math.h>

// and I changed it to this
#include </Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h>

此后,编译行g++ -std=c++17 client.cpp mathtest.pb.cc mathtest.grpc.pb.cc -o client 'pkg-config --libs --cflags protobuf grpc++' 现在返回以下错误:

ld: library not found for -lre2
clang: error: linker command failed with exit code 1 (use -v to see invocation)

看来我已经修复了 math.h 问题,并且发现了更多需要探索的内容。耶。

如果您认为这是一个坏主意,请有人插话。我知道这不是最明智的决定,考虑到它可能会影响未来的其他事情,但我找不到任何关于更改搜索目录顺序的内容。

最终更新:

终于让服务器工作了。只需将“re2”和“libcares”添加到我的编译命令中即可:

g++ -std=c++17 client.cpp mathtest.pb.cc mathtest.grpc.pb.cc -o client 'pkg-config --libs --cflags protobuf grpc++ re2 libcares'

两个月后从头开始构建东西的感觉真是太棒了......

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 2013-06-09
  • 2015-09-25
  • 1970-01-01
相关资源
最近更新 更多