Go中的共享库? [英] Shared library in Go?
问题描述
是否可以使用Go创建共享库(.so)?
Is it possible to create a Shared Library (.so) using Go?
已更新:创建了一个 issue 。
推荐答案
现在可以使用-linkshared标记
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
上面这些现在是什么,而不是静态链接所有东西,只是动态链接它们,而且最终会得到更小的编译文件。只是想给你一个想法,我的静态链接hello.go文件是2.3MB,而使用动态链接的相同代码只有12KB!
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中的共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!