“动态符号的意外 R_X86_64_64 重定位”使用Cgo时
我正在尝试使用 Cgo 创建 C 库的绑定。我有一个使用 Cgo 导入库并对其进行一些调用的包。它编译并安装得很好。但是,当尝试从 Go 程序使用该包时,链接时出现错误“动态符号的意外 R_X86_64_64 重定位”。
有什么想法吗?
I am trying to create binding for a C library using Cgo. I have package which uses Cgo to import the library and make some calls to it. It compiles and installs fine. But when trying to use that package from a Go program, I get the the error "unexpected R_X86_64_64 relocation for dynamic symbol" when linking.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它出现在 程序集生成
6g
编译器中的例程:R_X86_64_64
是库中符号的一种类型。有关amd64
架构中重定位的更多信息,请参阅第 ~70 页此处。是否可以将
386
编译库与amd64
代码混合使用?编译器应该报告导致问题的确切符号。您可以尝试链接包含其他符号的最小库,并尝试找到失败的最小示例吗?
您是否设法将
cgo
与任何库一起使用?It appears in the assembly generation routines in the
6g
compiler:The
R_X86_64_64
is a type of a symbol in the library. For more information about relocation in theamd64
architecture consult page ~70 here.Is it possible that you mix
386
compiled library withamd64
code?The compiler should report the exact symbol which caused the problem. Can you try linking with a minimal library containing other symbols, and try to locate a minimal example where it fails?
Did you manage to use
cgo
with any library at all?我同意 Elazar 的观点,即涉及 32 位和 64 位代码的混合似乎是合理的。
你试过gccgo吗?
I agree with Elazar that it seems plausible that mixing of 32-bit and 64-bit code is involved.
Have you tried gccgo?
工作起来就像一个魅力:
执行以下顺序:
之后创建一个包含以下内容的 /etc/profile.d/go.sh 并使其可执行:
然后重新启动 shell。任何源 xxx 都无法正常工作 - 请注意!在新的 shell 中执行以下操作:
执行该操作,然后将所有内容从 /usr/local/go 复制到 /var/go - 或者有一种方法可以通过符号链接合并两个目录,无论您喜欢什么。在上面的 go.sh 脚本中注释 GOROOT_FINAL 并再次重新启动 shell 后。并且您对最新的 Go 语言感到满意!
注意:需要重新启动两次 shell - 我自己发现它很困难。
Works like a charm :
do this sequence :
After that create a /etc/profile.d/go.sh with the follewing contents and make it executable:
And then restart your shell. NO source xxx will be working properly - be warned! In a new shell do this :
do the thing, and then copy all the things from /usr/local/go to /var/go - or there's a way to merge both directories by symlink, whatever you prefer. After that comment GOROOT_FINAL in go.sh script above AND restart your shell again. And you're ok with latest working Go language!
Note bene : Two shell restarts are required - found it myself in a hard way.