What are .a files in Go?

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

What are .a files in Go?

问题

在GO标准库中,我的Go安装目录下有源文件:

C:\Go\src\pkg

源文件夹下的包对应于这里的.a文件:

C:\Go\pkg\windows_amd64

.a文件是什么?它们用于什么以及如何生成它们。我注意到,当我执行go get libraryhostedingithub时,它们会自动生成。

英文:

In the GO standard library, there are source files under my Go installation:

C:\Go\src\pkg

The packages under the source folder corresponds to .a files in here:

C:\Go\pkg\windows_amd64

What are the .a files ? What are they used for and how are they generated. I noticed, that they get generated automatically when i do go get libraryhostedingithub.

答案1

得分: 31

它们是编译好的包。当你写import foo/bar时,你引用的就是这些文件。它指的是$GOROOT/pkg/$GOOS_$GOARCH/foo/bar.a,而不是$GOROOT/src/foo/bar/*.go

这些文件包含了编译好的包的二进制代码,以及调试符号和源代码信息。

英文:

They are compiled packages. It is these files you are referencing when you write import foo/bar. It refers to $GOROOT/pkg/$GOOS_$GOARCH/foo/bar.a and not $GOROOT/src/foo/bar/*.go.

These files contain the compiled package binary code, along with debug symbols and source information.

答案2

得分: 8

Go的.a包对象归档文件是通过go tool pack命令创建的:pack命令

英文:

Go .a package object archive files are created by the go tool pack command: Command pack.

答案3

得分: 7

根据文档

> 如果DIR是Go路径中列出的一个目录,那么具有源代码在DIR/src/foo/bar中的包可以作为“foo/bar”导入,并且其编译形式将安装到“DIR/pkg/GOOS_GOARCH/foo/bar.a”(或者对于gccgo,是“DIR/pkg/gccgo/foo/libbar.a”)。

所以它似乎只是编译/安装的包。

英文:

According to the docs:

> If DIR is a directory listed in the Go path, a package with source in DIR/src/foo/bar can be imported as "foo/bar" and has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a" (or, for gccgo, "DIR/pkg/gccgo/foo/libbar.a").

So it seems to be just the compiled/installed package.

答案4

得分: 5

如@peterSO所说,“Go的.a包对象归档文件是通过go tool pack命令创建的:Command pack”。

然而,为了更清楚,您可以复制这些文件并将扩展名改为.tar.gz,然后在像7zipLinux中的tar -xvf命令中打开它们作为常规压缩tar图像,或者您可以使用go tool pack,它实际上是相同的。

在里面,您会看到编译的对象文件“.o”,其中包含编译的代码和调试符号的体系结构,以及包定义文件(__.PKGDEF),其中包含包元数据。

英文:

As @peterSO said, "Go .a package object archive files are created by the go tool pack command: Command pack.".

However, to be even more clear, you can copy these files and rename the extension to .tar.gz and open them as a regular compressed tar image in a program like 7zip or the tar -xvf command in Linux, or you can use the go tool pack which is effectively the same.

Inside you'll see the compiled object files ".o" which contains the architecture compiled code and debug symbols, and the package definition file (__.PKGDEF) which contains the package metadata.

huangapple
  • 本文由 发表于 2013年3月21日 23:11:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/15551293.html
匿名

发表评论

匿名网友

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

确定