Ubuntu 22中缺失libdl.so导致程序崩溃的解决方法
解决Ubuntu 22.04中应用程序因libdl.so缺失崩溃的问题
问题现象
运行myapp时出现以下崩溃报错:
user@machine:~$ myapp Unhandled exception. System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl.so: cannot open shared object file: No such file or directory at Python.Runtime.Runtime.dlopen(String fileName, Int32 flags) at Python.Runtime.Runtime.<.cctor>g__OnResolveDllImport|46_0(String libraryName, Assembly assembly, Nullable`1 searchPath) in /tmp/tmp9xcr_e_u/pythonnet/2.5.1+ahl1/ws/src/src/runtime/runtime.cs:line 180 at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags) at Python.Runtime.Runtime.Py_IsInitialized() at Python.Runtime.Runtime.Initialize(Boolean initSigs) in /tmp/tmp9xcr_e_u/pythonnet/2.5.1+ahl1/ws/src/src/runtime/runtime.cs:line 195 at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs) in /tmp/tmp9xcr_e_u/pythonnet/2.5.1+ahl1/ws/src/src/runtime/pythonengine.cs:line 179 at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs) in /tmp/tmp9xcr_e_u/pythonnet/2.5.1+ahl1/ws/src/src/runtime/pythonengine.cs:line 156 at Python.Runtime.PythonEngine.InitExt() in /tmp/tmp9xcr_e_u/pythonnet/2.5.1+ahl1/ws/src/src/runtime/pythonengine.cs:line 266 Aborted (core dumped)
解决方案
在Ubuntu 22.04中,libdl.so是GNU C库(glibc)的组成部分,默认以带版本号的libdl.so.2形式存在,以下是两种常见解决方式:
1. 安装32位兼容库(适用于64位系统运行32位程序场景)
如果你的myapp是32位程序,需要安装32位glibc库:
sudo apt update && sudo apt install libc6-i386
2. 创建软链接(适用于64位程序场景)
64位系统中,libdl.so.2默认位于/lib/x86_64-linux-gnu/目录下,直接创建指向它的软链接即可:
sudo ln -s /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so
验证修复效果
运行以下命令确认libdl.so已可被系统识别:
ldconfig -p | grep libdl
输出应包含libdl.so和libdl.so.2的条目。
内容的提问来源于stack exchange,提问作者user5994461
相关产品推荐
相关产品推荐

