英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论