태그 보관물: macos-catalina

macos-catalina

Catalina C ++ : <cmath> 헤더를 사용하면 오류가 발생합니다 : 전역 네임 스페이스에 ‘signbit’이라는 멤버가 없습니다. -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OSX -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/include/Threading

Mojave에서 Catalina로 업그레이드 한 후 환경 설정 : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk

<cmath>헤더 를 사용하는 프로그램을 컴파일 할 수 없습니다 .

CFLAGS, CCFLAGS, CXXFLAGS를 변경하여 MacOSSDK 위치를 가리 키도록 변경하지 않았습니다.

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는 전역 네임 스페이스와 컴퓨터에 있습니다.

 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 헤더에도 다음이 포함됩니다.

 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 무엇입니까?

나는 이것이 잘못된 결과라고 확신합니다 CMAKE_OSX_SYSROOT. clang (CMake가 컴파일러 호출을 관리하지 않음)에 파이썬 바인딩을 사용할 때 설명하는 문제가 있었지만 CMake에서 다음을 수행하여 오류를 다시 만들었습니다.

set(CMAKE_OSX_SYSROOT "")  # Reset.

이 질문에 대한 답변을 따라 문제를 해결 했습니다. macOS Catalina로 업데이트 한 후 C ++ 코드로 R 패키지를 컴파일 할 수 없습니다 . .

요약 : Catalina에서는 /usr/includeSIP가 제거하고 보호합니다. 따라서 C 헤더를 찾을 것으로 예상되는 프로젝트는 컴파일에 실패합니다. 올바르게 기억한다면 Apple은 C 헤더가 필요한 프로젝트에 버그 보고서를 제출할 것을 권장합니다./usr/include .

컴파일하려는 코드의 빌드 시스템이 올바른 헤더를 가리켜 야합니다.

(1) Xcode가 최신인지 확인하십시오. Catalina의 오래된 Xcode가 빌드 환경에서 무엇을 할 수 있는지 말하지 않습니다.

(2) 의 결과 인 -isysroot /sdk/path컴파일러 플래그를 사용하십시오 . CMake의 모범 사례가 무엇인지 잘 모르겠지만 시도해보십시오./sdk/pathxcrun --show-sdk-path

set(CMAKE_OSX_SYSROOT /sdk/path)

또는

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

그래도 문제가 해결되면 CMake에서 더 좋은 방법을 찾고 싶을 것입니다.

물론 모험적이라면 내 질문에 대한 답변에서 제안한 것처럼 SIP를 비활성화 할 수도 있습니다 . macOS Catalina에서 / usr / include 누락 (Xcode 11 사용)


답변

iOS (MacBook Air 및 GitHub Actions 러너 모두)를 대상으로 시도하는 동안 동일한 문제가 발생하며 적절한 해결책을 제안하기 위해 Apple의 생태계에 익숙하지 않더라도 문제에 대한 몇 가지 추가 생각이 있습니다. 원래 명령 줄은 cpprestsdk의 CMake에서 왔지만 일단 필수 항목으로 요약하면 짧은 재현이 있습니다.

  1. cmath-bug.cpp안에 한 줄만있는 파일 을 만드 십시오 :
    #include <cmath>
  1. 실행 (일부 인수 앞의 줄 바꿈은 편의를위한 것이므로 제거하십시오)
clang -v -x c++ -target arm64-apple-ios13.2 -fcolor-diagnostics -std=c++11 -stdlib=libc++
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
-isystem  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
-c cmath-bug.cpp

내가 그것을 실행할 때, 나는 같은 문제에 직면 한 많은 사람들에게 친숙해진다.

Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: arm64-apple-ios13.2
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-ios13.2.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cmath-bug.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=13.2 -target-cpu cyclone -target-feature +fp-armv8 -target-feature +neon -target-feature +crypto -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -coverage-notes-file /Users/myuser/Projects/C++/cmath-bug.gcno -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/myuser/Projects/C++ -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=ios-13.2.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o cmath-bug.o -x c++ cmath-bug.cpp
clang -cc1 version 11.0.0 (clang-1100.0.33.16) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/Library/Frameworks"
ignoring duplicate directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks (framework directory)
End of search list.
In file included from cmath-bug.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318: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:319: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:320:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^

원래 명령 행에 전달하는 디렉토리는 2 개뿐입니다.

$ ls -alF /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
lrwxr-xr-x  1 root  wheel    12B Dec 17 11:54 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk@ -> iPhoneOS.sdk
$ ls -alF /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
total 2160
drwxr-xr-x  169 root  wheel   5.3K Dec 17 12:07 ./
drwxr-xr-x    5 root  wheel   160B Nov  4 19:22 ../
 ...
-rw-r--r--    9 root  wheel    32K Nov  4 19:52 math.h
 ...

그러나 여기서 흥미로운 점은 존재하지 않는 포함 디렉토리와 최종적으로 검색을 포함하는 포함 디렉토리 및 순서입니다. 내 생각에 명령 줄에 언급되지 않은 추가 디렉토리는 Apple 특정 논리에 따라 Apple Clang의 드라이버에 의해 삽입됩니다.

보고 된 오류에서 <cmath>헤더가 다음에 있음을 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath알 수 있습니다.

#include <__config>      // Line 304
#include <math.h>        // This one ends up causing troubles
#include <__cxx_version>

동일한 폴더 에 필요한 정의를 제공 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/하는 파일이 있다는 사실을 판단하면 다음과 math.h같습니다.

#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

#include_next <math.h>

#ifdef __cplusplus

// We support including .h headers inside 'extern "C"' contexts, so switch
// back to C++ linkage before including these C++ headers.
extern "C++" {

#include <type_traits>
#include <limits>

// signbit

#ifdef signbit

template <class _A1>
_LIBCPP_INLINE_VISIBILITY
bool
__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT
{
    return signbit(__lcpp_x);
}

#undef signbit

template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT
{
    return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
}

...

#elif defined(_LIBCPP_MSVCRT)
...
#endif  // signbit

의 저자 <cmath>을 기대하고 있었다 math.h같은 폴더에서 먼저 포함되어야 다음 #include_next <math.h>지시어는 특정 시스템을 찾을 수math.h . 그러나 실제로 일어나고있는 것은 아닙니다.

검색된 디렉토리에서 처음 2 개의 항목을 보면 :

#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1

시스템 특정 포함 디렉토리는 Clang이 주입 한 표준 라이브러리 디렉토리보다 위에 위치하므로 시스템 math.h라이브러리가 나머지 표준 라이브러리 헤더와 동일한 폴더에있는 것이 아니라 시스템 특정 디렉토리를 찾는 것 입니다. 표준 라이브러리 포함 디렉토리를 명령 행에 명시 적으로 추가하면 다른 두 디렉토리 전에 -isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1문제가 사라지고 파일을 컴파일 할 수 있기 때문일 수 있습니다. 그것은 Clang의 드라이버 또는 여기에 관련된 다른 것들이 자동으로 수행하는 것이 -internal-system아닙니다. 표준 라이브러리 디렉토리를 통해 (내부 플래그의 의미가 무엇인지 확실하지 않음) 시스템 디렉토리 뒤에 추가합니다.

이제 무시 된 디렉토리 목록을 보면 해당 목록의 첫 번째 항목은 다음과 같습니다.

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include/c++/v1"

c++/v1내 컴퓨터에 후행 부분이 존재하지 않기 때문에 iPhone SDK 설치가 c++경로의 기존 부분 내에 기호 링크 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++를 만들어 디렉토리를 가리 키 도록하여 모든 것이 작동 하는지 궁금해합니다 .

어쨌든, 나는 이것이 일어나고 있다고 생각하고 누군가가 이것을 올바르게 고치는 방법을 알고 있는지 궁금합니다.

감사합니다!

PS 상황에 따라 :

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ xcrun --show-sdk-path -sdk iphoneos13.2
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk


답변

Xcode 사본이 손상되었을 수 있습니다. 코 디자인으로 확인 :

codesign --verify /Applications/Xcode.app

이것은 나에게 일어 났고 문제는 Xcode가 손상되었습니다. 다시 설치하면 문제가 해결되었습니다.

무언가가 다음을 수정했습니다.

file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/scanner.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/decoder.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/encoder.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/__init__.cpython-37.pyc
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/math.h

math.h 위의 모든 장소에서 비어있었습니다.


답변

@solodon의 분석이 시작되었습니다. cmath파일 math.h에 헤더 파일의 검색 순서에 따라 잘못된 버전이 포함되어 있을 수 있습니다. 적어도 같은 오류가 발생했을 때 이런 일이 발생했습니다.

의 컴파일러 출력을 스캔하십시오 #include <...> search starts here:. 명령 행에서 (source)를 사용하여이 출력을 강제 실행할 수도 있습니다 .

gcc -Wp,-v -E -

다음과 같이 보일 것입니다 :

 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

경로 Toolchains가 앞에있는 경로 가 앞에있는 것을 주목하십시오 Platforms. 귀하의 경우 순서가 역전 된 경우, 구성의 원인을 파악해야합니다. 나를 위해, 그것은 명시적인 설정이었습니다CPLUS_INCLUDE_PATH 내 로그인 스크립트에서 .

위반 코드 :

XCBASE=`xcrun --show-sdk-path`
export CPLUS_INCLUDE_PATH=$XCBASE/usr/include

이것은 더 이상 SDK 헤더 파일에 대한 설치 패키지를 제공하지 않는 Xcode 11 문제를 해결하려는 시도의 일부였습니다. 이 코드를 제거한 후 cmathC ++ 코드에 성공적으로 포함시킬 수있었습니다 .

이 문제에 대한 해결책을 찾고자 여기에 온다면 다른 해결책이 필요할 수도 있지만 헤더 파일 검색 경로 순서와 같은 문제의 근본 원인을 밝히는 데 도움이되기를 바랍니다.


답변

명령을 사용하여 :

gcc -Wp,-v -E -

내 #include <…> 검색 순서 :

 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks (framework directory)

#include 오류의 이유는 다음과 같습니다.

 - #include<cmath> resides in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 - It includes <math.h>.
 - It searches /usr/local/include directory as this is the first directory to search. There is a math.h in "/usr/local/include/c++/9.3.0/" directory
 - It tries to use this.
 - But expectation was to use the math.h of the same directory /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 - The math.h of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 include math.h of /usr/local/include using #include_next<math.h>
 - As wrong math.h is included/linked with /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath, the compilation error happens

수정 :

    1. If we can alter the search order of #include<...> to search /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/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

# 2 옵션을 따랐으며 이제 빌드가 성공했습니다!

자세한 답변을 주신 solodon 에게 감사드립니다 . 나는 문제를 해결하기 위해 대답을 따랐다.


답변

내 프로젝트 안에 파일이 있음을 발견했습니다 math.h. 이름을 바꾼 후 문제가 사라졌습니다. 이음새 cmath에는 시스템 대신 내 파일이 포함됩니다.


답변

최근에 10.15.4 및 Xcode 11.4로 업그레이드 한 후 gRPC를 컴파일하려고 할 때이 오류가 발생했으며 제공된 모든 솔루션을 살펴보기 시작했습니다 (여기서 Catalina 10.15로 업그레이드 한 후 Mac에서 C 프로그램을 컴파일 할 수 없습니다 ) , 그들 중 일부를 시도했지만 ( /usr/include애플이 만들려고했던 분리를 위반하기 때문에 다시 만들려고하지는 않았지만 ) 아무 효과가없는 것 같습니다.

그런 다음 make프로세스가 생성 하는 실제 complier 호출을 자세히 살펴보고 명시 적이 있음을 알았습니다.

-I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include

결과적으로 포함이 잘못된 순서로 발생하게되었습니다.이 명시 적 포함 경로를 제거하면 예상대로 catalina, Xcode 및 Xcode 명령 줄 도구의 기본 설치로 컴파일이 성공했습니다. 다른 트릭 / 컴파일러 플래그는 없습니다. 필요합니다.