如何解决在安装GOPLS时出现“ld: framework not found CoreFoundation”错误?

huangapple go评论116阅读模式
英文:

How to solve the error ld: framework not found CoreFoundation while installing GOPLS?

问题

我正在使用的是 Apple M1 Pro 12.0.1 (21A559) 版本。
go 版本是:go1.19.3 darwin/arm64。

当我尝试安装 gopls 时,出现了以下错误。

go install -v golang.org/x/tools/gopls@latest

golang.org/x/tools/gopls
/usr/local/go/pkg/tool/darwin_arm64/link: 运行 clang 失败: 退出状态 1
ld: 找不到 CoreFoundation 框架
clang: 错误: 链接器命令执行失败,退出码为 1 (使用 -v 查看调用)

{
 "killed": false,
 "code": 2,
 "signal": null,
 "cmd": "/usr/local/go/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "go: 正在下载 golang.org/x/tools v0.3.0\ngo: 正在下载 golang.org/x/tools/gopls v0.10.1\ngo: 正在下载 golang.org/x/tools v0.2.1-0.20221101170700-b5bc717366b2\ngo: 正在下载 github.com/sergi/go-diff v1.1.0\ngo: 正在下载 honnef.co/go/tools v0.3.3\ngo: 正在下载 mvdan.cc/gofumpt v0.3.1\ngo: 正在下载 mvdan.cc/xurls/v2 v2.4.0\ngo: 正在下载 golang.org/x/sys v0.1.0\ngo: 正在下载 golang.org/x/mod v0.6.0\ngo: 正在下载 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4\ngo: 正在下载 golang.org/x/vuln v0.0.0-20221010193109-563322be2ea9\ngo: 正在下载 golang.org/x/text v0.4.0\ngo: 正在下载 golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e\ngo: 正在下载 golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e\ngo: 正在下载 github.com/BurntSushi/toml v1.2.0\ngo: 正在下载 github.com/google/go-cmp v0.5.8\n# golang.org/x/tools/gopls\n/usr/local/go/pkg/tool/darwin_arm64/link: 运行 clang 失败: 退出状态 1\nld: 找不到 CoreFoundation 框架\nclang: 错误: 链接器命令执行失败,退出码为 1 (使用 -v 查看调用)\n\n"
} 
英文:

I am using Apple M1 Pro 12.0.1 (21A559).
with go version : go1.19.3 darwin/arm64

When I am trying to install gopls, I get the following error.

go install -v golang.org/x/tools/gopls@latest

golang.org/x/tools/gopls
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: framework not found CoreFoundation
clang: error: linker command failed with exit code 1 (use -v to see invocation)

{
 "killed": false,
 "code": 2,
 "signal": null,
 "cmd": "/usr/local/go/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "go: downloading golang.org/x/tools v0.3.0\ngo: downloading golang.org/x/tools/gopls v0.10.1\ngo: downloading golang.org/x/tools v0.2.1-0.20221101170700-b5bc717366b2\ngo: downloading github.com/sergi/go-diff v1.1.0\ngo: downloading honnef.co/go/tools v0.3.3\ngo: downloading mvdan.cc/gofumpt v0.3.1\ngo: downloading mvdan.cc/xurls/v2 v2.4.0\ngo: downloading golang.org/x/sys v0.1.0\ngo: downloading golang.org/x/mod v0.6.0\ngo: downloading golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4\ngo: downloading golang.org/x/vuln v0.0.0-20221010193109-563322be2ea9\ngo: downloading golang.org/x/text v0.4.0\ngo: downloading golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e\ngo: downloading golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e\ngo: downloading github.com/BurntSushi/toml v1.2.0\ngo: downloading github.com/google/go-cmp v0.5.8\n# golang.org/x/tools/gopls\n/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1\nld: framework not found CoreFoundation\nclang: error: linker command failed with exit code 1 (use -v to see invocation)\n\n"
} 

答案1

得分: 2

clang --version命令中的Target是指目标平台。在这个例子中,初始时Target是x86_64-apple-darwin22.2.0,后来通过删除错误的二进制文件后,Target变为arm64-apple-darwin22.2.0,这是正确的目标平台。

英文:

What is the Target in clang --version?

I had the same issue and found that the clang binary (I was mistakenly using from a python conda env) had a Target of x86_64-apple-darwin22.2.0. I deleted that binary from my python env and then the clang binary from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin was picked up.

So before I had:

~/ ❯ clang --version                                                                                                                                                      Py base
clang version 13.0.1
Target: x86_64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Users/robtaylor/opt/anaconda3/envs/py38/bin

Then after I deleted the unwanted binary using rm /Users/robtaylor/opt/anaconda3/envs/py38/bin/clang* I had:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

So the Target was arm64-apple-darwin22.2.0, which is now correct.

huangapple
  • 本文由 发表于 2022年12月2日 13:03:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/74651094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定