alpine arm64 与 e_sqlite3' or one of its dependencies 异常解决方法

2020年12月10日 6243点热度 3人点赞 0条评论
内容目录

Microsoft 官方的 Docker 镜像不能直接运行 EFCore,会出现异常:

      System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
       ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       ---> System.DllNotFoundException: Unable to load shared library 'e_sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libe_sqlite3: No such file or directory
         at System.Runtime.InteropServices.NativeLibrary.LoadByName(String libraryName, QCallAssembly callingAssembly, Boolean hasDllImportSearchPathFlag, UInt32 dllImportSearchPathFlag, Boolean throwOnError)
         at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError)
         at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath)
         at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
         at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
         at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
         at SQLitePCL.Batteries_V2.Init()
         --- End of inner exception stack trace ---
         at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
         at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
         at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
         at Microsoft.Data.Sqlite.SqliteConnection..cctor()

file

我们在 Linux 中,打开程序目录的 runtimes 中,找到 linux-arm64 目录,执行 ldd 命令,检测 .so 文件的依赖:

 ldd libe_sqlite3.so
        /lib/ld-musl-aarch64.so.1 (0xffffa9187000)
        libc.so.6 => /lib/ld-musl-aarch64.so.1 (0xffffa9187000)
Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by libe_sqlite3.so)
Error relocating libe_sqlite3.so: __memcpy_chk: symbol not found
Error relocating libe_sqlite3.so: __memset_chk: symbol not found

发现 缺少 libc 库,可执行以下命令安装:

 apk add libc6-compat

重启程序或容器,即可正常使用。
file

痴者工良

高级程序员劝退师

文章评论