簡體   English   中英

C++:錯誤:全局命名空間中沒有名為“signbit”的成員

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

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

這只是正在出現的其他內容的一小部分。 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
  • 本文所述,更改 CMath 文件中的 #include <math.h> 鏈接。

修復:

  1. 如果我們可以先把#include<...>的搜索順序改為搜索>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/inclu>de/c++/v1,可以是固定的。

  2. 在 /Applications/Xcode.app/Contents/ 中使用 #include</Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h> 而不是 <math.h>開發者/工具鏈/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 問題,而不是配置/設置問題。 任何幫助將不勝感激。

經過一番挖掘,我發現最有可能出錯的地方......

我在終端中執行gcc -Wp,-v -E -以查看以什么順序搜索了哪些路徑。

這是 output:

#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 問題,並且發現了更多需要探索的內容。 耶。

如果您認為這是一個壞主意,請有人加入。 我知道這不是最明智的決定,因為它可能會影響未來的其他事情,但我找不到任何關於更改搜索目錄順序的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM