Home >Backend Development >Golang >What is .a file in golang
.a file is generated during the compilation process. Each package will generate a corresponding .a file. Go When compiling, first determine whether the source code of the package is If there are changes, if not, the .a file will not be recompiled, which can speed up the process.
Generate .a file (.h file will also be automatically generated)
Create file pkgqrcode.go
package mainimport "C"import ( //"fmt" "github.com/tuotoo/qrcode" "os")//export GetQrcodeStringfunc GetQrcodeString(cstring *C.char) *C.char { //func GetQrcodeString() *C.char { path := C.GoString(cstring) //path := "qrcode.png" fi, err := os.Open(path) if err != nil { //fmt.Println(err.Error()) return C.CString(path) } defer fi.Close() qrmatrix, err := qrcode.Decode(fi) if err != nil { //fmt.Println(err.Error()) return C.CString(path) } //fmt.Println(qrmatrix.Content) //return C.Cstring(qrmatrix.Content) gostr := qrmatrix.Content cstr := C.CString(gostr) return cstr}func main() {}
The function of import "C" is When using C functions in go code
you need to add //export GetQrcodeString to generate the .h file (don’t know what!!)
C.GoString(cstring) Convert C string to go String
C.CString(gostr) Convert go string to C string
Compilation steps
Generate .a file command (enter pkgqrcode.go code directory) Execution:
go build -buildmode=c-archive -o pkgqrcode.a pkgqrcode.go
Generate results
##pkgqrcode.aFor more golang knowledge, please pay attention topkgqrcode.h
golang tutorialcolumn.
The above is the detailed content of What is .a file in golang. For more information, please follow other related articles on the PHP Chinese website!