doulupian8725 2013-09-22 03:26
浏览 23
已采纳

如何从Go库中获取对象构建信息?

I'm trying to build a Go program where I have a required library on my system in binary form. However, go build fails with

object is [linux amd64 go1.1.1 X:none] expected [linux amd64 go1.1.2 X:none]

I see what the immediate problem is: the static library was built with an older version of Go. How can I read that information from the .a file directly? (I can see it with strings library.a | grep '^go object', but is there something that's meant to output the build string? (And, what is that string properly called?)

  • 写回答

1条回答 默认 最新

  • dongtiandexue123456 2013-09-22 15:18
    关注

    The .a files the Go compiler produces are managed using the pack tool. The metadata used to link the package is found in the __.PKGDEF member of the archive.

    You can extract this file from an archive to stdout with:

    go tool pack p path/to/package.a __.PKGDEF
    

    It starts with the build signature you're after, so you could either take the first line or grep for ^go object as you were with the output of strings (this should be a bit more reliable, in case that text shows up as a constant in the program code).

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

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码