I am trying to use some third party dll in go language. But facing enormous difficulties. I would prefer pure go implementation but that is not a choice.
This my sample program
import (
"fmt"
"github.com/andlabs/dl"
)
type GetObject func(string, string) int
func main() {
gro := new(GetObject)
d, err := dl.Open("/home/vaishnavi/lib/libVsphere.so", dl.Lazy)
if err!=nil{
panic(err)
}
fmt.Println("DLL Loaded::", d)
s, err := d.Symbol("GetSum")
if err != nil {
panic(err)
}
gro = (*GetObject)(s)
p := (*gro)("1","2")
fmt.Println("Got returned result::", p)
fmt.Println("Converted::", gro)
fmt.Println("Loaded at::", s)
if s == nil {
fmt.Println("Error loading from the dll")
}
}
While running this program i am getting following error
DLL Loaded:: 15028848
unexpected fault address 0x0
fatal error: fault
[signal 0xb code=0x80 addr=0x0 pc=0x401923]
goroutine 1 [running]:
runtime.gothrow(0x4dcef0, 0x5)
/usr/local/go/src/runtime/panic.go:503 +0x8e fp=0xc20805fda0 sp=0xc20805fd88
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:29 +0x265 fp=0xc20805fdf0 sp=0xc20805fda0
main.main()
/home/vaishnavi/ESXI_VHBS/src/main/main.go:25 +0x343 fp=0xc20805ff98 sp=0xc20805fdf0
runtime.main()
/usr/local/go/src/runtime/proc.go:63 +0xf3 fp=0xc20805ffe0 sp=0xc20805ff98
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc20805ffe8 sp=0xc20805ffe0
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
Error: process exited with code 2.
Any help will be appreciated.
The package documentation says:
Symbol looks up the given named symbol in the Module. Note that the value of Symbol can be nil, so checking symbol for nil will not indicate an error; checking err for nil is.
(Emphasis added.)
From the package's source code it seems that there are only two reasons both Symbol and err can be nil
. Either the symbol is really null, or it doesn't exist in the library. Make sure that the symbol is really there, and that you've not misspelled the name. Usually you can list all symbols in an .so
file with readelf -Ws
or nm -g
.