我可以在Go中使用共享对象吗?

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

Can I use shared objects with Go?

问题

我可以在Go中使用共享对象吗?

英文:

Can I use shared objects with Go?

答案1

得分: 6

根据Go FAQ,你可以使用“外部函数接口”调用C库:

>Go程序是否可以与C/C++程序链接?
>
>Go有两个编译器实现,6g和其它相关工具,通称为gc,还有gccgo。gc使用不同的调用约定和链接器,因此只能与使用相同约定的C程序进行链接。有这样的C编译器,但没有C++编译器。Gccgo是GCC的前端,可以与使用GCC编译的C或C++程序链接,但是由于Go是垃圾回收的,这样做是不明智的,至少是天真的。
>
>有一个“外部函数接口”可以安全地从Go代码中调用C编写的库。我们希望使用SWIG将此功能扩展到C++库。目前还没有安全的方法可以从C或C++调用Go代码。

回答你之前关于Windows DLL的问题:目前没有Go的Windows实现。更多信息请阅读can-go-compiler-be-installed-on-windows

英文:

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

huangapple
  • 本文由 发表于 2010年2月13日 04:09:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/2254777.html
匿名

发表评论

匿名网友

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

确定