duandongji2231 2015-04-22 14:04
浏览 31
已采纳

穿线工具抱怨档案头错误

I am trying to use go generate/stringer (golang.org/x/tools/cmd/stringer) to generate String() methods on enums. I have problems, which I believe, are because of slightly different format of .a packages on different systems. I have this file:

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)
}

Now if I run go generate example.go on my machine everything is all right: foo_string.go is created. However, on a test machine I get:

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)

Now, after some digging in the code I think that I get this error, because on my machine rand.a has the following header:

!<arch>
__.PKGDEF       0           0     0     644     2051   

` while on test machine it has the following header:

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

`

I think that the crucial difference is slash after PKGDEFF. gcimporter refuses to process .a file, if it doesn't have __.PKGDEF header.

To check this, I edited manually gcimporter/exportdata.go and changed one of the line from this:

if name != "__.PKGDEF"

to this:

if name != "__.PKGDEF" && name != "__.PKGDEF\"

After this change (and compiling and installing everything) I was able to run go generate on example.go.

My questions are: why do I get this problem and how do I get rid of it (other then manually editing external library)?

  • 写回答

1条回答 默认 最新

  • dqu3974 2015-05-03 11:38
    关注

    What I can see from the spec for openSUSE's packaging they are disabling reinstallation of the standard library at updates. __.PKGDEF is a Go specific informational section, and some linker OpenSUSE has used has simply produced incompatible output.

    There's nothing you can do except install a healthy Go from the official source.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行