Can I use shared objects with Go?

廉价感情. 提交于 2019-12-11 03:40:02

问题


Can I use shared objects with Go?


回答1:


According to the Go FAQ, you can call into C libraries using a "foreign function interface":

Do Go programs link with C/C++ programs?

There are two Go compiler implementations, 6g and friends, generically called gc, and gccgo. Gc uses a different calling convention and linker and can therefore only be linked with C programs using the same convention. There is such a C compiler but no C++ compiler. Gccgo is a GCC front-end that can, with care, be linked with GCC-compiled C or C++ programs. However, because Go is garbage-collected it will be unwise to do so, at least naively.

There is a “foreign function interface” to allow safe calling of C-written libraries from Go code. We expect to use SWIG to extend this capability to C++ libraries. There is no safe way to call Go code from C or C++ yet.

To answer your earlier question about Windows DLL's: no, as there is currently not a windows implementation of Go. For more information, read can-go-compiler-be-installed-on-windows



来源:https://stackoverflow.com/questions/2254777/can-i-use-shared-objects-with-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!