“动态符号的意外 R_X86_64_64 重定位”使用Cgo时

发布于 2024-11-10 16:44:55 字数 133 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

合约呢 2024-11-17 16:44:55

它出现在 程序集生成 6g 编译器中的例程:

case 256 + R_X86_64_64:
        if(targ->dynimpname != nil && !targ->dynexport)
                diag("unexpected R_X86_64_64 relocation for dynamic symbol %s",
                     targ->name);
        r->type = D_ADDR;
        return;

R_X86_64_64 是库中符号的一种类型。有关 amd64 架构中重定位的更多信息,请参阅第 ~70 页此处

是否可以将 386 编译库与 amd64 代码混合使用?

编译器应该报告导致问题的确切符号。您可以尝试链接包含其他符号的最小库,并尝试找到失败的最小示例吗?

您是否设法将 cgo 与任何库一起使用?

It appears in the assembly generation routines in the 6g compiler:

case 256 + R_X86_64_64:
        if(targ->dynimpname != nil && !targ->dynexport)
                diag("unexpected R_X86_64_64 relocation for dynamic symbol %s",
                     targ->name);
        r->type = D_ADDR;
        return;

The R_X86_64_64 is a type of a symbol in the library. For more information about relocation in the amd64 architecture consult page ~70 here.

Is it possible that you mix 386 compiled library with amd64 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?

分分钟 2024-11-17 16:44:55

我同意 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?

绻影浮沉 2024-11-17 16:44:55

工作起来就像一个魅力:

root@Ubuntu-1304-raring-64-minimal:/etc# uname -a
Linux Ubuntu-1304-raring-64-minimal 3.8.13.4 #2 SMP Mon Jul 8 23:59:05 CEST 2013 x86_64 x86_64 x86_64 GNU/Linux

执行以下顺序:

cd /usr/local
mkdir /var/go
apt-get install mercurial
hg clone https://code.google.com/p/go/

之后创建一个包含以下内容的 /etc/profile.d/go.sh 并使其可执行:

export GOPATH=/var/go
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export GOROOT_FINAL=/var/go
export GOHOSTARCH=amd64
export GOARCH=amd64
export CGO_ENABLED=1

然后重新启动 shell。任何源 xxx 都无法正常工作 - 请注意!在新的 shell 中执行以下操作:

cd /usr/local/go/src
./make.bash

执行该操作,然后将所有内容从 /usr/local/go 复制到 /var/go - 或者有一种方法可以通过符号链接合并两个目录,无论您喜欢什么。在上面的 go.sh 脚本中注释 GOROOT_FINAL 并再次重新启动 shell 后。并且您对最新的 Go 语言感到满意!

root@Ubuntu-1304-raring-64-minimal:/usr/work/golang/go/src# go version
go version devel +35d5bae6aac8 Fri Oct 18 10:45:19 2013 +0400 linux/amd64

注意:需要重新启动两次 shell - 我自己发现它很困难。

Works like a charm :

root@Ubuntu-1304-raring-64-minimal:/etc# uname -a
Linux Ubuntu-1304-raring-64-minimal 3.8.13.4 #2 SMP Mon Jul 8 23:59:05 CEST 2013 x86_64 x86_64 x86_64 GNU/Linux

do this sequence :

cd /usr/local
mkdir /var/go
apt-get install mercurial
hg clone https://code.google.com/p/go/

After that create a /etc/profile.d/go.sh with the follewing contents and make it executable:

export GOPATH=/var/go
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export GOROOT_FINAL=/var/go
export GOHOSTARCH=amd64
export GOARCH=amd64
export CGO_ENABLED=1

And then restart your shell. NO source xxx will be working properly - be warned! In a new shell do this :

cd /usr/local/go/src
./make.bash

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!

root@Ubuntu-1304-raring-64-minimal:/usr/work/golang/go/src# go version
go version devel +35d5bae6aac8 Fri Oct 18 10:45:19 2013 +0400 linux/amd64

Note bene : Two shell restarts are required - found it myself in a hard way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文