douzhi3779 2015-07-21 15:29
浏览 128

使用DLL API时出现意外故障地址0x0

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.

  • 写回答

1条回答 默认 最新

  • dtkwt62022 2015-07-21 15:52
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗