开发者

Dynamic FFI in Go

Is it possible to dynamically load foreign C library (开发者_Go百科dll) and call its functions in Go?

I know there is cgo which is used to statically bind to C functions, but I'm interested in dynamic way.


Short answer: no. (at least not with gc, gccgo is gcc linkable however, so it might be possible)

Medium answer: However, you can statically bind, say, libffi or libdl and then use it to dynamically load other libraries.

Long answer: You can write go packages in C and ASM using the go toolchains C compiler and assembler (see src/pkg/runtime for example). So you could write a FFI in either C or ASM as a go package.

Edit: From the comments below (also CW now)

Alternatively, it can be done using the syscall and unsafe packages (easily in windows, but I imagine it would be harder in linux and not far off from the third solution above).

http://code.google.com/p/go/wiki/CallingWindowsDLLs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜