This is a created article in which the information may have evolved or changed.
There are two types of libraries: static libraries (. A,. lib) and dynamic libraries (. So,. dll)
Golang does not seem to support dynamic libraries (pending confirmation ...) )
The package in Go
The first thing to know about your environment variables [Gopath]
Create the following directory under [Gopath] Directory
/bin
/pkg
/src
New Folder MyMath in SRC
[Gopath]/src/mymath/math.go
package mymathimport ("fmt")// Sqrt returns an approximation to the square root of x.func Add() {//大写,才能被外界调用fmt.Println("===package mymath Add func ")}
[Gopath]/src/main.go
package mainimport ("fmt""mymath")func main() {//var f float = 2.3mymath.Add()fmt.Printf("Hello, world~~~ \n")}
And then
$ go installGenerate a static library ([GOPATH]/PKG/.../MYMATH.A)
$ go build main.goBuild Program
$ mainLast Run