Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go Stringer工具抱怨归档头错误_Go - Fatal编程技术网

Go Stringer工具抱怨归档头错误

Go Stringer工具抱怨归档头错误,go,Go,我正在尝试使用go generate/stringer(golang.org/x/tools/cmd/stringer)在枚举上生成String()方法。我有问题,我相信这是因为不同系统上.a包的格式略有不同。我有这个档案: package main import ( "math/rand" ) //go:generate stringer -type=Foo type Foo int; const ( FooPrime Foo = iota FooBis ) f

我正在尝试使用go generate/stringer(
golang.org/x/tools/cmd/stringer
)在枚举上生成String()方法。我有问题,我相信这是因为不同系统上.a包的格式略有不同。我有这个档案:

package main

import (
    "math/rand"
)

//go:generate stringer -type=Foo
type Foo int;

const (
    FooPrime Foo = iota
    FooBis
)

func main() {
    //Just use rand anywhere, otherwise we get a compiler error
    rand.Seed(1)
}
现在,如果我在我的机器上运行go generate example.go,一切正常:foo_string.go被创建。但是,在测试机器上,我得到:

stringer: checking package: example.go:4:2: could not import math/rand (reading export data: /usr/lib64/go/pkg/linux_amd64/math/rand.a: go archive is missing __.PKGDEF)
现在,在深入研究代码之后,我认为我得到了这个错误,因为在我的机器上rand.a有以下标题:

!<arch>
__.PKGDEF       0           0     0     644     2051   
!<arch>
__.PKGDEF/      0           399   399   100644  2051  

`
为此:

if name != "__.PKGDEF" && name != "__.PKGDEF\"
在这次更改(以及编译和安装所有内容)之后,我能够在example.go上运行go generate


我的问题是:为什么我会遇到这个问题,如何解决它(除了手动编辑外部库)

从openSUSE的封装规范中我可以看到,他们正在禁用标准库的更新重新安装。PKGDEF是一个特定于Go的信息部分,OpenSUSE使用的某些链接器只是生成了不兼容的输出


除了从官方来源安装一个健康的Go,你什么也做不了。

我误读了路径,没有意识到这是在GOROOT中。您是否可以尝试在两个系统上重建Go,或者至少确保它们具有完全相同的Go版本?(我想这也是你吗?虽然还没有回应)是的,之前我试过吃果仁,但运气不好,所以我写了这么多。我不认为这是围棋版本的问题。调试此问题时,我将go-on远程计算机的版本从
1.2
更新为
1.4.2
。在这两种情况下,.a文件的头中都有u.PKGDEF\而不是u.PKGDEF。路径
/usr/lib64/go
有点不寻常。GOROOT应该在你的系统上吗?(另外,如果是的话,您不应该设置GOROOT env变量)。是的,在我的测试机器上,GOROOT位于
/usr/lib64/go
中。这是openSUSE机器,go是使用rpm软件包安装在那里的。我不是openSUSE方面的专家,但我认为安装目录(因此GOROOT)是由rpm包指定的,而不是由系统管理员指定的。无论如何,这个奇怪的_uu.PKGDEF\头可能与openSUSE专门为/编译的代码有关,因为似乎其他地方都是_uuu.PKGDEF。看起来openSUSE对Go的构建做了一些不同的事情。除非你们想开始对他们的rpm构建进行故障排除,否则我会放弃这一点,转而支持正式的二进制版本(或者从源代码构建,这很容易)。
if name != "__.PKGDEF" && name != "__.PKGDEF\"