macOS升级Catalina后 gcc无法正常编译文件问题

macOS升级为Catalina后,原本gcc却出现了如下错误

$> gcc
dyld: Symbol not found: _OBJC_IVAR_$_NSFont._fFlags
  Referenced from: /Applications/Xcode.app/Contents/Frameworks/IDEFoundation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
  Expected in: /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
 in /Applications/Xcode.app/Contents/Frameworks/IDEFoundation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
gcc: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
gcc: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

根据提示应该是在/Applications/…那一长串中引用的符号找不到,应该在/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit。注意到下面的

gcc: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

因此先输入这个看看:

> sudo xcode-select
xcode-select: error: no command option given
Usage: xcode-select [options]

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).

Options:
  -h, --help                  print this help message and exit
  -p, --print-path            print the path of the active developer directory
  -s , --switch   set the path for the active developer directory
  --install                   open a dialog for installation of the command line developer tools
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path

先用-p看一下目前的path

> sudo xcode-select -p
/Applications/Xcode.app/Contents/Developer

根据前面的提示把这个改成后面的,键入如下指令

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

ok,gcc可以正常用了。
至于后面那个路径是我是如何知道的,参考:
https://stackoverflow.com/questions/58278260/cant-compile-a-c-program-on-a-mac-after-upgrading-to-catalina-10-15/58278392#

你可能感兴趣的:(macOS)