Shared library in Go?

jldupont picture jldupont · Nov 18, 2009 · Viewed 23.2k times · Source

Is it possible to create a Shared Library (.so) using Go?

UPDATED: created an "issue" for it.

Answer

Reza picture Reza · Jan 28, 2016

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!