dongzhong2018 2018-05-30 21:00
浏览 22
已采纳

仅二进制库不包括依赖项

I'm attempting to build a binary-only library that includes some dependencies. The build of the binary-only library itself goes great, but it doesn't actually include my dependencies: when I try to use the library on a system without the dependencies installed, I am given an error saying they are missing.

For reference, the command I'm using to build the library is:

go build -o build/pkg/<os>_<arch>/<path/to/binary>.a

I then write my stub <library>.go file to build/src/<path/to/binary>.go.

The stub file contains stubbed implementations of all public methods and an import block for its dependencies, with each dependency included in that import block.

The stub file also has the // go:binary-only-package line above the package directive.

If there is a way to build a binary library that will include its dependencies I'd appreciate it!

  • 写回答

1条回答 默认 最新

  • dongyi4170 2018-05-30 21:21
    关注

    As you know, go compiles packages into individual archive files and creates a binary from those. Go recently allowed you to supply only the archives without the source code (normally go would recompile from source if the source is newer).

    It is possible to combine several archives into one, as described here:

    How to merge two "ar" static libraries into one

    The problem is that go's compiler will find symbols using the folder and file structure that matches the package names. So, if you combine archives, the go compiler will no longer be able to locate symbols when building a binary. Only one of the packages will be locatable depending on the location of the archive. So it is not possible to do what you are requesting, at least with the current go compiler support.

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

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line