dylib icon indicating copy to clipboard operation
dylib copied to clipboard

在linux里面调用so库。 cannot open shared object file: No such file or directory

Open 601630051 opened this issue 2 years ago • 4 comments

`package main

import ( "fftest/dylib" "fmt" "os" "runtime" "sync" )

// #cgo CFLAGS: -I./number // #cgo LDFLAGS: -L${SRCDIR} -lnumber var avformatDll *dylib.LazyDLL var avformatDllOnce sync.Once

func main() { libPath, _ := os.Getwd() avformatPath := "" if runtime.GOOS == "linux" { os.Setenv("LD_LIBRARY_PATH", libPath+"/lib/linux") avformatPath = libPath + "/lib/linux/libavformat.so.58" } else { os.Setenv("LD_LIBRARY_PATH", libPath+"/lib/window") avformatPath = libPath + "/lib/window/avformat-58.dll" }

fmt.Println("avformatPath=", avformatPath)
avformatDllOnce.Do(func() {
	avformatDll = dylib.NewLazyDLL(avformatPath)
})
//avformatDll.NewProc("")

} `

在window平台是可以编译成功。但是在linux平台不行。 dlopen err: libavcodec.so.58: cannot open shared object file: No such file or directory [root@192_168_2_221 fftest]# avformatPath= /home/go/1/fftest/lib/linux/libavformat.so dlopen err: libavcodec.so.58: cannot open shared object file: No such file or directory

我感觉是因为libavformat.so.58和其他模块关联有关系造成,无法找到其他库。要如何解决这个问题。谢谢

601630051 avatar Mar 30 '23 13:03 601630051

应该是这个so的依赖问题吧。。。这个libavcode.so.58应该是只是个入口文件,你得查下依赖才知道

ying32 avatar Mar 30 '23 14:03 ying32

谢谢 查到问题了。LD_LIBRARY_PATH 需要设置这个编译链接,但是在go里面不知道怎么设置。类似在export LD_LIBRARY_PATH 我现在用os.Setenv("LD_LIBRARY_PATH","具体的所有so库路径"),但是不行。

zhangyc  @.***

 

------------------ 原始邮件 ------------------ 发件人: "ying32/dylib" @.>; 发送时间: 2023年3月30日(星期四) 晚上10:10 @.>; 抄送: "zhangyc @.@.>; 主题: Re: [ying32/dylib] 在linux里面调用so库。 cannot open shared object file: No such file or directory (Issue #4)

应该是这个so的依赖问题吧。。。这个libavcode.so.58应该是只是个入口文件,你得查下依赖才知道

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

601630051 avatar Mar 31 '23 01:03 601630051

应该是这个so的依赖问题吧。。。这个libavcode.so.58应该是只是个入口文件,你得查下依赖才知道

我想问问,有没办法在linux里面,动态的链接到so库之类的?在代码里面配置

601630051 avatar Apr 09 '23 07:04 601630051

代码里应该就是环境变量了吧。。。 或者当前目录下

ying32 avatar Apr 10 '23 13:04 ying32