在golang中创建dll/so/dylib的基本示例/资源。

huangapple go评论100阅读模式
英文:

Looking for basic example / resource on how to create a dll/so/dylib in golang

问题

我正在寻找将我用golang编写的应用程序的一部分转换为dll/dylib/so,并从我的核心golang应用程序中调用它。

有人知道如何做到这一点的好资源或指南吗?因为我的搜索没有找到太多信息(我找到的大部分是关于这个功能的旧请求,我知道现在已经包含了)

请注意:我已经看过如何进行实际构建的文档,但我缺少的是如何组织应用程序和公开方法的信息。

如果有人有类似经验,我也对这种方法的优缺点感兴趣。

英文:

I am looking to convert part of an app I have written in golang to a dll/dylib/so and make calls to it from my core golang app.

Does anyone know of any good resources or guides on how to do this as my searches are not turning up a great deal of info (much of what I'm finding are old requests for the feature which i understand is now included)

Please note: I have seen documentation on how to do the actual build, it is more around how to organise the app and expose methods that I am missing

I would also be interested in pros/cons of this approach if anyone has any experience doing something similar

答案1

得分: 1

c-shared buildmode 目前只支持 Linux。

如此处所示,https://stackoverflow.com/questions/40573401/building-a-dll-with-go-1-7,你可以使用 gcc 构建 DLL 或共享库,但 Go 工具链不直接支持。

然而,如果你想创建一个“插件”架构,你不需要创建一个 C 共享库,其中每个实例都会创建一个新的 Go 运行时。已经有一个 plugin 专门用于此目的。

英文:

The c-shared buildmode is currently only supported on Linux.

As seen here, https://stackoverflow.com/questions/40573401/building-a-dll-with-go-1-7, you may be able to build a DLL or shared lib using gcc, but it's not supported directly by the Go toolchain.

However, if you're looking to create a "plugin" architecture, you don't want to create a C shared library, in which each instance creates a new Go runtime. There is already a plugin package which is intended for that purpose.

huangapple
  • 本文由 发表于 2017年7月14日 23:56:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/45107175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定