package main
/*#include <dlfcn.h>
int do_test_so_func(int a,int b)
{
void* handle;
typedef int (*FPTR)(int,int);
handle = dlopen("./test_so.so", 1);
FPTR fptr = (FPTR)dlsym(handle, "test_so_func");
int result = (*fptr)(a,b);
dlclose(handle);
return result;
}
#cgo LDFLAGS: -ldl
*/
import "C"
import "fmt"
func main() {
fmt.Println("20*30=", do_test_so_func(20, 30))
}
func do_test_so_func(a int, b int) int {
return int(C.do_test_so_func(C.int(a), C.int(b)))
}
我暂时想到的就这样了
在C里面直接把动态库里的函数调出来,然后在Go里面包装函数。。
除非你自己包装dlopen和dlsym,但是C里面的函数指针在Go里面不知道要怎么办— —。。