开发者

Shared library in Go?

开发者 https://www.devze.com 2022-12-11 15:34 出处:网络
Is it possible to create a Shared Library (.so) using Go? UPDATED: created an \"issue\" for i开发者_如何学Pythont.This is possible now using -linkshared flag

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

UPDATED: created an "issue" for i开发者_如何学Pythont.


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."


Possible now! I built a .so file using Go and then imported into python quite easily! Here is an articles that I liked: http://www.darkcoding.net/software/building-shared-libraries-in-go-part-1/


Apparently, it now is possible, but only under very precise set of circumstances. More precisely, if you're writing for the Android platform.

The "goandroid" project on GitHub provides a set of patches that allows Go to build a shared library for specific use with the Android NDK. See https://github.com/eliasnaur/goandroid

0

精彩评论

暂无评论...
验证码 换一张
取 消