<p>I’m considering Go for a new project that is supposed to be usted by other languages. So, the solution seems to be to create a shared library (Linux only).</p>
<p>I know this can be done with cgo, but I would like to see a real project that uses the same model. </p>
<p>Does anyone knows about a project that is used as a shared library?</p>
<hr/>**评论:**<br/><br/>kostix: <pre><blockquote>
<p>the solution seems to be to create a shared library (Linux only).
I know this can be done with cgo</p>
</blockquote>
<p>This is not correct: the Go compiler supports a special "build mode" called "c-shared" which produces a shared library with C-style API.
The <code>cgo</code> subsystem is not involved in this process (in the sense you don't use <code>import "C"</code> and stuff); you just supply the <code>-buildmode=c-shared</code> command-line option to the compiler — see <a href="https://golang.org/doc/go1.5#link" rel="nofollow">this</a> and <a href="https://golang.org/doc/go1.6#compiler" rel="nofollow">this</a>. </p></pre>igknighted: <pre><p>Working example test I did for something I was trying out recently. I did a c-archive instead of a shared library, but the principal is similar. </p>
<p><a href="https://gist.github.com/protosam/edcc00cc309b5f4a163ece39c46d9e4a" rel="nofollow">https://gist.github.com/protosam/edcc00cc309b5f4a163ece39c46d9e4a</a></p></pre>tv64738: <pre><p>That'll still need the Go runtime active, it won't behave like a C library. I would recommend against trying to embed Go in another language.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传