Как исправить проблему невидимых заголовков XCode и компилятора Clang в MacOS? - PullRequest
0 голосов
/ 25 апреля 2020

G CC - Apple Clang версии 11.0.3 (clang-1103.0.32.29) дает мне странные результаты, когда я пытаюсь запустить любую программу C ++ / C. Например, запустив этот код:

#include <string>
#include <iostream>

int main()
{
    std::string hello = "Hello world";
    std::cout << hello << std::endl;
    return 0;
}

Я запускаю с g cc или g ++

gcc template.cpp -o template

Это дает мне эту ошибку

In file included from template.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:439:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:624:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/initializer_list:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stddef.h:50:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__nullptr:23:29: error: variable has incomplete type 'struct _LIBCPP_TEMPLATE_VIS'
struct _LIBCPP_TEMPLATE_VIS nullptr_t
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__nullptr:23:8: note: forward declaration of 'std::__1::_LIBCPP_TEMPLATE_VIS'
struct _LIBCPP_TEMPLATE_VIS nullptr_t
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__nullptr:23:38: error: expected ';' after top level declarator
struct _LIBCPP_TEMPLATE_VIS nullptr_t
                                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__nullptr:46:52: error: unknown type name 'nullptr_t'
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
                                                   ^
In file included from template.cpp:2:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/istream:163:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:140:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/locale:192:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:167:44: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:110:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:135:9: note: using declaration
using ::abs;
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:169:44: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:112:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:135:9: note: using declaration
using ::abs;
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:172:42: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:115:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:143:9: note: using declaration
using ::div;
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:174:42: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:117:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
                                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:143:9: note: using declaration
using ::div;
        ^
7 errors generated.

Я думаю, Я вызвал это, когда пытался скопировать некоторые заголовочные файлы библиотеки в /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

Теперь я не могу скомпилировать любую программу C ++ на моем Ma c. Я не могу понять, как это исправить.

Я попытался установить llvm и добавить его путь, но ничего не помогает.

> brew install llvm   
==> Installing dependencies for llvm: libffi
==> Installing llvm dependency: libffi
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.3.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libffi-3.3.catalina.bottle.tar.gz
==> Caveats
libffi is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find libffi you may need to set:
  export LDFLAGS="-L/usr/local/opt/libffi/lib"
  export CPPFLAGS="-I/usr/local/opt/libffi/include"

For pkg-config to find libffi you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/libffi/3.3: 16 files, 489.4KB
==> Installing llvm
==> Downloading https://homebrew.bintray.com/bottles/llvm-10.0.0_3.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ea/ea9b9f579df49499d9ab0084e10edecc5350298d6c5db399a1dabc8694dab7db?__gda__=exp=1587779777~hmac=fa0024a2581a685070cc1612da34abc29c53c8c352dce2f47c74d841c
######################################################################## 100.0%
==> Pouring llvm-10.0.0_3.catalina.bottle.tar.gz
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

==> Summary
?  /usr/local/Cellar/llvm/10.0.0_3: 7,055 files, 1GB

> echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc
> export LDFLAGS="-L/usr/local/opt/llvm/lib"
> export CPPFLAGS="-I/usr/local/opt/llvm/include"
~                                                                                                                                                                                                       

Текущие версии установленного Clang:

> gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> g++ version

1 Ответ

0 голосов
/ 25 апреля 2020

Ну, я нашел решение. Ранее я использовал приложение XCode и испортил некоторые библиотечные файлы, когда пытался скопировать заголовочные файлы в /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

. Это оказалось настолько фатальным, что я был совершенно беспомощен. Ни мой код C ++, ни C не скомпилировался бы, ни Node Applications не скомпилировались бы из-за gyp.

Видимо, было еще несколько ошибок, когда я пытался переустановить несколько вещей, и мой домашний напиток дал страницу, полную ошибок с непокрытыми заголовочными файлами.

Решение:

Я удалил приложение Xcode, переключился на инструмент командной строки. Удалил llvm, и это сработало.

Вам нужно переключить путь XCode, вы делаете это:

sudo xcode-select --switch /Library/Developer/CommandLineTools

Вы хороши для go, и никогда не связывайтесь с файлами внутри SDK, иначе это будет стоить вам часов c. Приветствия.

...