Calling functions in an so file from Go

前端 未结 3 1066
再見小時候
再見小時候 2020-12-31 14:30

Is it possible to call a static object (.so) file from Go? I\'ve been searchign Google and I keep hitting upon the claim that I can do

lib, _ := syscall.Load         


        
3条回答
  •  悲&欢浪女
    2020-12-31 15:04

    On a POSIX platform, you could use cgo to call dlopen and friends:

    // #cgo LDFLAGS: -ldl
    // #include 
    import "C"
    
    import fmt
    
    func foo() {
         handle := C.dlopen(C.CString("libfoo.so"), C.RTLD_LAZY)
         bar := C.dlsym(handle, C.CString("bar"))
         fmt.Printf("bar is at %p\n", bar)
    }
    

提交回复
热议问题