"DllNotFoundException: libc"尝试在快照包中运行单声道应用程序时



尝试将单声道应用程序捆绑在快照包中时,当应用程序尝试发出简单的HTTP请求时,我收到此异常:

System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: libc
at (wrapper managed-to-native) System.Platform:uname (intptr)
at System.Platform.CheckOS () [0x00022] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Platform.get_IsMacOS () [0x0000a] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetSystemWebProxy () [0x00149] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetDefaultWebProxy () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.get_DefaultWebProxy () [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.GlobalProxySelection.get_Select () [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.HttpWebRequest..ctor (System.Uri uri) [0x0008d] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:.ctor (System.Uri)
at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x00006] in <41c316444c8a4380b9344ba09eeb18de>:0 
at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0006a] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000f3] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.DllNotFoundException: libc
at (wrapper managed-to-native) System.Platform:uname (intptr)
at System.Platform.CheckOS () [0x00022] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Platform.get_IsMacOS () [0x0000a] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetSystemWebProxy () [0x00149] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetDefaultWebProxy () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.get_DefaultWebProxy () [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.GlobalProxySelection.get_Select () [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.HttpWebRequest..ctor (System.Uri uri) [0x0008d] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:.ctor (System.Uri)
at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x00006] in <41c316444c8a4380b9344ba09eeb18de>:0 
at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0006a] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000f3] in <41c316444c8a4380b9344ba09eeb18de>:0 <---
System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: libc
at (wrapper managed-to-native) System.Platform:uname (intptr)
at System.Platform.CheckOS () [0x00022] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Platform.get_IsMacOS () [0x0000a] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetSystemWebProxy () [0x00149] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetDefaultWebProxy () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.get_DefaultWebProxy () [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.GlobalProxySelection.get_Select () [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.HttpWebRequest..ctor (System.Uri uri) [0x0008d] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:.ctor (System.Uri)
at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x00006] in <41c316444c8a4380b9344ba09eeb18de>:0 
at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0006a] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000f3] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.DllNotFoundException: libc
at (wrapper managed-to-native) System.Platform:uname (intptr)
at System.Platform.CheckOS () [0x00022] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Platform.get_IsMacOS () [0x0000a] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetSystemWebProxy () [0x00149] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.GetDefaultWebProxy () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.WebRequest.get_DefaultWebProxy () [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.GlobalProxySelection.get_Select () [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at System.Net.HttpWebRequest..ctor (System.Uri uri) [0x0008d] in <bd46d4d4f7964dfa9beea098499ab597>:0 
at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:.ctor (System.Uri)
at System.Net.Http.HttpClientHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x00006] in <41c316444c8a4380b9344ba09eeb18de>:0 
at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x0006a] in <41c316444c8a4380b9344ba09eeb18de>:0 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000f3] in <41c316444c8a4380b9344ba09eeb18de>:0 <---

snapcraft.yaml 看起来像这样:

name: foo
base: core18 # the base snap is the execution environment for this snap
version: '0.3.1.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: bar
description: |
baz
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: strict
apps:
foo:
command: bin/foo
parts:
foo:
plugin: dump
source: ./staging
stage-packages:
- mono-complete

我以这种方式创建快照:

./configure.sh --prefix=./staging
make
make install
snapcraft

我试图通过将与libc相关的软件包捆绑到快照中并将它们添加到stage-packages来解决此问题:

stage-packages:
- mono-complete
- libc6
- libc6-dev
- libc-dev-bin
- libc-bin

但问题仍然存在。如果我尝试用布局映射这些:

layout:
/lib/x86_64-linux-gnu:
bind: $SNAP/lib/x86_64-linux-gnu
/usr/lib:
bind: $SNAP/usr/lib

然后我崩溃了:

$ snap run foo
execv failed: No such file or directory

也许/usr/lib 映射太多了,但如果我将其限制为此:

layout:
/lib/x86_64-linux-gnu:
bind: $SNAP/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu:
bind: $SNAP/usr/lib/x86_64-linux-gnu

然后我仍然得到DllNotFoundException。

我终于用这个提交解决了这个问题:

https://github.com/nblockchain/geewallet/commit/cba6abf52eaf2709b8b6a974079ac5713fd3aeec

最重要的一点是将其放在应用程序的启动器脚本中:

if [[ $SNAP ]]; then
PKG_DIR=$SNAP/usr

我发现,至少我需要设置MONO_CONFIG+MONO_GAC_PREFIX.

这可以通过在主应用程序部分添加环境部分来完成。

apps:
myapp:
command: _some_command_to_run_mono_app
environment:
MONO_CONFIG: "$SNAP/etc/mono/config"
MONO_CFG_DIR: "$SNAP/etc"
MONO_GAC_PREFIX: "$SNAP/usr/lib/mono/gac"

更多信息

最新更新