使用Golang编译主包代码和.a文件的方法是什么?

huangapple go评论91阅读模式
英文:

Golang compile with main package code and .a files?

问题

在我的情况下,我需要发布我的库项目,但不包含源代码,只有编译后的形式。

给定以下条件:

  • 一些以编译后的 .a 文件形式存在的库包
  • 一个以源代码形式存在的主包
  • 所有它们构建的平台类型匹配

是否可能将主包编译并将其与 .a 文件链接成一个可执行文件?如果可行,应该如何操作?

英文:

In my scenario I'll need to release my lib project without source code but a compiled form.
Given,

  • Some library package in the form of compiled .a files,
  • a main package in form of source code,
  • all their platform types where they're built on match,

is it possible to compile the main and link it with .a files up into an executable? How to do it if doable?

答案1

得分: 1

除非“.a”文件是通过“安装”(go get或go install)一个包生成的,否则不行。一个“.a”库文件是根据将要使用它的环境的操作系统、机器架构、go版本等进行“定制”的。你的库的用户可能不满足所有的要求。因此,没有源代码的“.a”文件是没有用的,可能还有其他原因。

英文:

Not unless the .a files were generated as a result of "installing" (go get or go install) a package. A ".a" library file is "customized" for the OS, machine architecture, go version etc. of the environment in which it will be used. Users of your library are not likely to meet all of the requirements. For that reason, and perhaps others, ".a" files without source code are not useful.

huangapple
  • 本文由 发表于 2014年9月18日 10:34:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/25903292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定