Alpine(Wayland)环境下Rust winit应用无法运行求助
Alpine Linux + MUSL工具链下winit窗口初始化失败问题
我正在跟着教程在Alpine Linux系统上用Rust创建基于winit的窗口应用。最初执行cargo run无法编译,安装build-base cmake musl-dev libpng-dev freetype-dev fontconfig-dev后编译成功,但运行时抛出如下错误:
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoWaylandLib X11 status: LibraryOpenError(OpenError { kind: Library, detail: "opening library failed (Dynamic loading not supported); opening library failed (Dynamic loading not supported)" })', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:719:9
我推测这是MUSL无法使用动态库导致的,但不知道怎么解决(编译成功但无法运行)。
系统信息
- 操作系统:Linux 5.15.80-0-lts,Alpine v3.17 x86_64
- 窗口管理器:sway(Wayland)
- Rust工具链:stable-x86_64-unknown-linux-musl,rustc 1.65.0
- Shell:ash
已尝试的操作
- 安装了Xorg和GUI开发库
libxtst-dev libxext-dev libxrender-dev freetype-dev fontconfig-dev libxslt glib-dev musl-dev libxcursor-dev libxi-dev libx11-dev glu-dev glew-dev mesa-dev libxcb-dev libxkbcommon-dev libx11-dev xproto lbxft-dev libxext-dev libxcb-dev libxkbcommon-dev,无效 - 使用
RUSTFLAGS="-C target-feature=-crt-static"运行应用,无效 - 使用
RUSTFLAGS="-C target-feature=+crt-static"尝试静态编译,抛出异常 - 使用
RUSTFLAGS="-C target-feature=-crt-static"编译运行,虽能运行但无窗口显示,且每次修改代码都会触发依赖全量重新编译
我没找到针对Alpine或MUSL环境的相关文档,希望安装正确依赖后程序能正常编译并显示窗口,求帮助。
Cargo.toml 配置
[package] name = "gpu-programming" version = "0.1.0" edition = "2021" [dependencies] wgpu = ">=0.14" winit = ">=0.27" env_logger = ">=0.10" log = ">=0.4"
main.rs 代码
use winit::{ event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event_loop::{ControlFlow, EventLoop}, window::WindowBuilder, }; pub fn main() { env_logger::init(); // Make sure WGPU errors are printed to console. Else it will fail silently! // Create event loop and window let event_loop = EventLoop::new(); let window = WindowBuilder::new() .build(&event_loop) .expect("Failed to create window"); println!("Window created! {:?}", window.id()); window.set_visible(true); println!("Visible {:?}", window.is_visible()); println!("Monitor: {:?}", window.current_monitor()); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { ref event, window_id, } if window_id == window.id() => match event { WindowEvent::CloseRequested | WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, virtual_keycode: Some(VirtualKeyCode::Escape), .. }, .. } => *control_flow = ControlFlow::Exit, _ => {} }, _ => {} }); }
内容的提问来源于stack exchange,提问作者maurict
相关产品推荐
相关产品推荐

