无法安装gopls:clang-12链接器报错问题求助
安装gopls失败问题及解决方案
问题现象
- VSCode内点击图标安装gopls失败
- 执行CLI命令
go install -v golang.org/x/tools/gopls@latest同样失败,报错如下:
# golang.org/x/tools/gopls /usr/local/go/pkg/tool/darwin_arm64/link: running x86_64-apple-darwin13.4.0-clang failed: exit status 1 ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libresolv.tbd' for architecture arm64 clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
环境信息
$ go version go version go1.21.6 darwin/arm64 $ gopls -v version bash: gopls: command not found $ go env GO111MODULE='' GOARCH='arm64' GOBIN='' GOCACHE='/Users/xxx/Library/Caches/go-build' GOENV='/Users/xxx/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/xxx/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='darwin' GOPATH='/Users/xxx/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.21.6' GCCGO='gccgo' AR='x86_64-apple-darwin13.4.0-ar' CC='x86_64-apple-darwin13.4.0-clang' CXX='x86_64-apple-darwin13.4.0-clang++' CGO_ENABLED='1' GOMOD='/dev/null' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/yh/d_jgns49545bkkpm4rst2c_80000gn/T/go-build3182514498=/tmp/go-build -gno-record-gcc-switches -fno-common'
VSCode安装失败输出
Tools environment: GOPATH=/Users/xxx/go Installing 1 tool at /Users/xxx/go/bin gopls Installing golang.org/x/tools/gopls@latest FAILED { "code": 1, "killed": false, "signal": null, "cmd": "/usr/local/go/bin/go install -v golang.org/x/tools/gopls@latest", "stdout": "", "stderr": "# golang.org/x/tools/gopls\n/usr/local/go/pkg/tool/darwin_arm64/link: running x86_64-apple-darwin13.4.0-clang failed: exit status 1\nld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libresolv.tbd' for architecture arm64\nclang-12: error: linker command failed with exit code 1 (use -v to see invocation)\n\n" } 1 tools failed to install. gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /usr/local/go/bin/go install -v golang.org/x/tools/gopls@latest # golang.org/x/tools/gopls /usr/local/go/pkg/tool/darwin_arm64/link: running x86_64-apple-darwin13.4.0-clang failed: exit status 1 ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libresolv.tbd' for architecture arm64 clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
解决方案
方案1:更新Command Line Tools
报错核心是旧版本Command Line Tools不支持arm64架构下的tapi文件类型,执行以下步骤:
- 终端运行
softwareupdate --list查看可用更新 - 找到Command Line Tools更新项,执行
softwareupdate --install "Command Line Tools for Xcode"完成更新 - 更新后重新执行
go install -v golang.org/x/tools/gopls@latest
方案2:临时禁用CGO
若暂时无法更新工具,可绕过CGO依赖的clang链接问题:
- 执行命令:
CGO_ENABLED=0 go install -v golang.org/x/tools/gopls@latest,强制使用纯Go编译
方案3:修复SDK路径
- 查看当前SDK路径:
xcrun --show-sdk-path - 若路径指向旧版本,执行
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer(需已安装Xcode) - 或重新安装Command Line Tools:
xcode-select --install
内容的提问来源于stack exchange,提问作者Zztk
相关产品推荐
相关产品推荐

