C++: error: no member named 'signbit' in the global namespace

C++: error: no member named 'signbit' in the global namespace

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

目标: 编译纯 C++ gRPC client-server 应用程序

错误:

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;
      ~~^

这只是正在出现的其他内容的一小部分。 cmath 还有一些错误,但我认为一旦实施解决方案,大多数(如果不是全部)将被清除。

我尝试过的:

#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

The fix:

  1. If we can alter the search order of #include<...> to search >/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/inclu>de/c++/v1 at first, it can be fixed.

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

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++'

配置:

                 ,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 问题而不是 configuration/setup 问题。如有任何帮助,我们将不胜感激。

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

我在我的终端中执行了 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++' 现在 returns 出现以下错误:

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'

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