调用Go库的C代码

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

Calling Go library from C Code

问题

我找到了很多关于如何使用cgo从Go调用C库的信息,但我对相反的情况很感兴趣:在Go中编写一个库,并在各种C程序中进行链接和使用。

这种情况是否可行?有没有相关的好资源可以参考?谢谢。

英文:

I've found a ton of information about how to use cgo to call C libraries from Go, but I'm interested in the opposite: writing a library in Go, and linking/using it in various C programs.

Is this possible? Any good resources for this? Thanks.

答案1

得分: 1

目前无法实现这个。Go必须是入口点,并且如果不使用gccgo,就无法将Go编译为共享库。

有一个提案正在改变这一点,所以在某个时候可能会有这个选项。请参考这个文档了解详情。

英文:

This can not be done currently. Go has to be the entry point and without the use of gccgo, you can't compile Go into a shared library.

There is a proposal to change this, so it may or may not be an option at some point. Refer to this document for details.

huangapple
  • 本文由 发表于 2015年2月17日 23:59:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/28565609.html
匿名

发表评论

匿名网友

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

确定