Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are .a files in Go?

Tags:

go

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.

like image 512
Dante Avatar asked Mar 21 '13 15:03

Dante


People also ask

Whats a .Go file?

Source code for a program written in Go, a programming language originally developed by Google; contains code written in plain text format that must be compiled before being run as a program. Go is loosely based off of the programming language C, which uses the . C file extension for its source code.

What are Go files called?

GO is the filename extension of a file containing source code written in Go (commonly called Golang) programming language. The file can be created with a code editor such as Vim or Sublime and executed with go command line utility.

How do I read a file in Go?

The simplest way of reading a text or binary file in Go is to use the ReadFile() function from the os package. This function reads the entire content of the file into a byte slice, so you should be careful when trying to read a large file - in this case, you should read the file line by line or in chunks.

How do packages work in Go?

Go programs are organized into packages. A package is a collection of source files in the same directory that are compiled together. Functions, types, variables, and constants defined in one source file are visible to all other source files within the same package. A repository contains one or more modules.


1 Answers

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.

like image 131
jimt Avatar answered Sep 23 '22 12:09

jimt