登录
首页 >  Golang >  Go问答

clang: 错误: 链接器执行命令失败,退出码为1

来源:stackoverflow

时间:2024-03-18 08:54:25 416浏览 收藏

**摘要:** 在使用 Go 构建代码时,出现“链接器执行命令失败,退出码为 1”错误,表明 clang 无法成功链接程序。虽然程序在运行时可以正常工作,但链接时出现了重复符号的问题。为了调试此问题,可以使用 `-v` 标志查看更详细的日志。此外,错误可能与在同一包中同时运行包函数和包名称有关,需要将包函数重命名以避免冲突。

问题内容

我正在尝试构建我的代码。当我尝试执行以下操作时: go build 我收到以下错误:

/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking.
ld: warning: text-based stub file /System/Library/Frameworks//IOKit.framework/Versions/A/IOKit.tbd and library file /System/Library/Frameworks//IOKit.framework/Versions/A/IOKit are out of sync. Falling back to library file for linking.
duplicate symbol _FetchPEMRootsCTX509_MountainLion in:
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000033.o
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000036.o
duplicate symbol _FetchPEMRootsCTX509 in:
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000033.o
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000036.o
duplicate symbol _useOldCodeCTX509 in:
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000033.o
    /var/folders/v8/94mqr56n2yqd9pcj8rd21cyr0000gp/T/go-link-418396971/000036.o
ld: 3 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

尝试搜索这个问题,但找不到任何结论性的东西。有人可以帮我吗:

  1. 这个错误是怎么回事?由于我的程序运行良好,如 go run 完美运行。
  2. 如何调试它?例如,是否还有更多我可以使用的标志来为我提供额外的日志?我尝试了 go build -v ,输出是相同的。

解决方案


出现此错误的原因之一是您正在运行同一包的函数以及包名称。示例:

package server

...

server.functionofsamepackage()

因此将其更新为:

package server

...

functionOfSamePackage()

以上就是《clang: 错误: 链接器执行命令失败,退出码为1》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>