【发布时间】: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
链接。
修复:
如果我们可以先将#include<...>的搜索顺序改为搜索>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/inclu>de/c++/v1,可以修。
使用 #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