Is it possible to dynamically load foreign C library (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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With