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
.
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.
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.
Go .a
package object archive files are created by the go tool pack
command: Command pack.
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.