Ошибки зависимостей компиляции C

#c #macos #visual-studio-code #gcc #compiler-errors

Вопрос:

Я недавно по какой-то причине обновил gcc [версия 11.2.0_1], и он удалил файлы из предыдущей версии gcc. Это привело к некоторым проблемам в моем коде редактора VS. Я начал получать ошибки includePath.

Чтобы исправить их, я попытался отредактировать путь включения в конфигурации, и когда это не сработало, я попытался добавить файл заголовка, который не удалось открыть, вручную, получив исходный код в Интернете и поместив его в файл в каталоге в пути включения. Однако было слишком много файлов, которые VS Code не мог открыть. Поэтому я не мог создавать их вручную по одному.

Итак, я, наконец, попытался изменить путь компилятора в конфигурации на «usr/bin/clang», и это сработало. Я перестал получать ошибки в коде VS.

Теперь главная проблема. После устранения проблемы с включением пути я не могу ничего скомпилировать. Вот что говорит компилятор, когда я запускаю g hello-world.cpp :

 In file included from hello-world.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:85: /usr/local/include/stdlib.h:38:12: error: no member named 'abort' in namespace 'std' using std::abort;  ~~~~~^ /usr/local/include/stdlib.h:39:12: error: no member named 'atexit' in namespace 'std' using std::atexit;  ~~~~~^ /usr/local/include/stdlib.h:40:12: error: no member named 'exit' in namespace 'std' using std::exit;  ~~~~~^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:100:9: error: no member named 'div_t' in the global namespace using ::div_t;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:101:9: error: no member named 'ldiv_t' in the global namespace using ::ldiv_t;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:103:9: error: no member named 'lldiv_t' in the global namespace using ::lldiv_t;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:105:9: error: no member named 'atof' in the global namespace using ::atof;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:106:9: error: no member named 'atoi' in the global namespace using ::atoi;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:107:9: error: no member named 'atol' in the global namespace using ::atol;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:109:9: error: no member named 'atoll' in the global namespace using ::atoll;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:111:9: error: no member named 'strtod' in the global namespace; did you mean 'strtok'? using ::strtod;  ~~^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:90:7: note: 'strtok' declared here char *strtok(char *__str, const char *__sep);  ^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:112:9: error: no member named 'strtof' in the global namespace; did you mean 'strtok'? using ::strtof;  ~~^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:90:7: note: 'strtok' declared here char *strtok(char *__str, const char *__sep);  ^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:113:9: error: no member named 'strtold' in the global namespace using ::strtold;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:114:9: error: no member named 'strtol' in the global namespace; did you mean 'strtok'? using ::strtol;  ~~^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:90:7: note: 'strtok' declared here char *strtok(char *__str, const char *__sep);  ^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:116:9: error: no member named 'strtoll' in the global namespace; did you mean 'strcoll'? using ::strtoll;  ~~^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:78:6: note: 'strcoll' declared here int strcoll(const char *__s1, const char *__s2);  ^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:118:9: error: no member named 'strtoul' in the global namespace using ::strtoul;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:120:9: error: no member named 'strtoull' in the global namespace; did you mean 'strcoll'? using ::strtoull;  ~~^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:78:6: note: 'strcoll' declared here int strcoll(const char *__s1, const char *__s2);  ^ In file included from main.cpp:1: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/iostream:37: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/ios:215: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__locale:14: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string:504: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/string_view:175: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/__string:57: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/algorithm:643: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:653: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/typeinfo:60: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/exception:81: /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:125:9: error: no member named 'rand' in the global namespace using ::rand;  ~~^ /Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/cstdlib:126:9: error: no member named 'srand' in the global namespace using ::srand;  ~~^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.  

Я действительно расстроен этим. Есть ли способ переустановить gcc, чтобы вместе с ним появились все зависимости и эта проблема исчезла?

Редактировать: вот мой вывод для gcc -v

 $ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c  /4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.2) Target: x86_64-apple-darwin21.1.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin  

Комментарии:

1. Я думаю, что ваша проблема заключается в конфликте между вашей версией gcc и sdk, который вы установили в macOS. Пожалуйста, подождите других, я не эксперт по macOS.

2. Это имеет смысл, но я не понимаю, что именно вызвало проблему в первую очередь. Я добавил только некоторые файлы заголовков вручную.

3. Вы недавно обновили свой CLT или ОС? Это явно не пивные пути.

4. @sweenish да. Я переехал в Монтерей две недели назад. Однако это не повлияло на компиляцию. Все пошло наперекосяк только после того, как я заварил обновленный gcc

5. Можете ли вы отредактировать свой вопрос, чтобы включить вывод gcc --version ? Кроме того, поскольку это C так, вы действительно должны использовать g , а не gcc .