Is it possible to create a Shared Library (.so) using Go?
UPDATED: created an "issue" for it.
Go allows linking against C libraries or pasting in in-line code.
There is plenty of packages or libraries for Go programming that supports developers in the production of application programs.
Check your GOPATH in environment variables and set it to the directory which contains all Go files. Create a new folder with the name of the package you wish to create. In the folder created in step 2, create your go file that holds the Go package code you wish to create.
This is possible now using -linkshared
flag
What you need to do is to first run this command:
go install -buildmode=shared -linkshared std
(Above code makes all common packages shareable!) then
go install -buildmode=shared -linkshared userownpackage
finally when compiling your code you need to run:
go build -linkshared yourprogram
What the above those is now it rather than statically linking everything only dynamically links them and you will end up with much smaller compiled files. Just to give you an idea my "hello.go" file with static linking is 2.3MB while the same code using dynamic linking is just 12KB!
Go Execution Modes describes Building Go Packages as a shared library:
"In this mode a Go package, or set of packages, may be built as a shared library. A Go program that imports one or more of those Go packages may be linked against this shared library. The shared library may be changed between the time the Go program is linked and the time it is run; the shared library that is available when the program starts is the one that will be used...
In the Go 1.5 release this is implemented for the linux-amd64 target only. When using gccgo it is implemented for any supported target."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With