0

Such similar question was posted 6 yrs ago (How to import and use .so file in golang program)

I guess the current releases would have looked into this.

I have to call network.so from my Go code.

One of the function under network.so

bool Tape::test1(obj a,obj b) {
}

My current implementation

/* #cgo LDFLAGS: -ldl
 #include <dlfcn.h>
*/

func main() {
   handle := C.dlopen(C.CString("network.so"), C.RTLD_LAZY)
   //How to call C.test1 function ? 
}

Looking for some examples.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Amelia
  • 41
  • 5
  • 2
    Here's [a library](https://pkg.go.dev/github.com/coreos/pkg/dlopen) that abstracts over `dlopen`. And see some [github code](https://github.com/search?l=Go&q=dlopen&type=Code) on using it. If you prefer using `C.dlopen` directly, see [some source code](https://sourcegraph.com/search?q=C.dlopen+lang%3Ago&patternType=literal) doing exactly that. – thwd Mar 05 '21 at 10:40
  • @thwd, thank you. Will look into this – Amelia Mar 05 '21 at 11:07
  • 2
    Have look at this https://golang.hotexamples.com/examples/c/-/dlopen/golang-dlopen-function-examples.html – Sweety Mar 05 '21 at 11:13
  • Do you have to use dlopen? Can you just link the library at compile time? – JimB Mar 05 '21 at 12:38

0 Answers0