doufu1970 2010-11-09 10:28
浏览 203
已采纳

Go中的动态FFI

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.

  • 写回答

1条回答 默认 最新

  • doubi7346 2010-11-10 13:09
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 想用@vueuse 把项目动态改成深色主题,localStorge里面的vueuse-color-scheme一开始就给我改成了dark,不知道什么原因(相关搜索:背景颜色)
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题