Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No backend is available" error with examples #1236

vanzef opened this issue Aug 5, 2018 · 1 comment


Copy link

commented Aug 5, 2018

I am trying to build and run an example from, here is the code fore reference:

extern crate piston_window;

use piston_window::*;

fn main() {
    let mut window: PistonWindow = 
        WindowSettings::new("Hello Piston!", [640, 480])
    while let Some(e) = {
        window.draw_2d(&e, |c, g| {
            clear([1.0; 4], g);
            rectangle([1.0, 0.0, 0.0, 1.0], // red
                      [0.0, 0.0, 100.0, 100.0],
                      c.transform, g);

but get error:

     Running `target/debug/example`
thread 'main' panicked at 'No backend is available', /home/user/.local/share/cargo/registry/src/
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/
   1: std::sys_common::backtrace::print
             at libstd/sys_common/
             at libstd/sys_common/
   2: std::panicking::default_hook::{{closure}}
             at libstd/
   3: std::panicking::default_hook
             at libstd/
   4: std::panicking::rust_panic_with_hook
             at libstd/
   5: std::panicking::begin_panic
             at /checkout/src/libstd/
   6: winit::platform::platform::EventsLoop::new
             at /home/user/.local/share/cargo/registry/src/
   7: winit::EventsLoop::new
             at /home/user/.local/share/cargo/registry/src/
   8: glutin_window::GlutinWindow::new
             at /home/user/.local/share/cargo/registry/src/
   9: <glutin_window::GlutinWindow as window::BuildFromWindowSettings>::build_from_window_settings
             at /home/user/.local/share/cargo/registry/src/
  10: window::WindowSettings::build
             at /home/user/.local/share/cargo/registry/src/
  11: <piston_window::PistonWindow<W> as window::BuildFromWindowSettings>::build_from_window_settings
             at /home/user/.local/share/cargo/registry/src/
  12: window::WindowSettings::build
             at /home/user/.local/share/cargo/registry/src/
  13: example::main
             at src/
  14: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/
  15: std::panicking::try::do_call
             at libstd/
             at libstd/
  16: __rust_maybe_catch_panic
             at libpanic_unwind/
  17: std::rt::lang_start_internal
             at libstd/
             at libstd/
             at libstd/
  18: std::rt::lang_start
             at /checkout/src/libstd/
  19: main
  20: __libc_start_main
  21: _start
             at ../sysdeps/x86_64/start.S:120

I am running NixOS, so problem may be with dynamically loading libraries. Is there a way to find out which
libs do I need?

As far as I can understand the problem is in XConnection::new function:

    pub fn new(error_handler: XErrorHandler) -> Result<XConnection, XNotSupported> {
        // opening the libraries
        let xlib = try!(ffi::Xlib::open());
        let xcursor = try!(ffi::Xcursor::open());
        let xrandr = try!(ffi::Xrandr_2_2_0::open());
        let xrandr_1_5 = ffi::Xrandr::open().ok();
        let xinput2 = try!(ffi::XInput2::open());
        let xlib_xcb = try!(ffi::Xlib_xcb::open());

        unsafe { (xlib.XInitThreads)() };
        unsafe { (xlib.XSetErrorHandler)(error_handler) };

        // calling XOpenDisplay
        let display = unsafe {
            let display = (xlib.XOpenDisplay)(ptr::null());
            if display.is_null() {
                return Err(XNotSupported::XOpenDisplayFailed);

        Ok(XConnection {
            xlib: xlib,
            xrandr: xrandr,
            xrandr_1_5: xrandr_1_5,
            xcursor: xcursor,
            xinput2: xinput2,
            xlib_xcb: xlib_xcb,
            display: display,
            latest_error: Mutex::new(None),

I've tried to explicitly "install" all mentioned libs via nix-shell -p "[x11 gcc] ++ (with xorg; [libXcursor xrandr xinput libxcb])", but got the same error as above.

@vanzef vanzef changed the title `No backend is available` error with examples "No backend is available" error with examples Aug 5, 2018

This comment has been minimized.

Copy link

commented Sep 21, 2019

The source of the issue is glutin. More details available in this closed issue.

I fixed the issue myself by building a simple nix package in the root of the cargo directory:

  nixpkgs = import <nixpkgs> {};
  inherit (nixpkgs) mesa libGL patchelf rustPlatform wayland xorg;
  inherit (xorg) libX11 libXcursor libXi libXxf86vm;
rustPlatform.buildRustPackage rec {
  pname = "spinning-square";
  version = "0.1.0";

  src = ./.;

  cargoSha256 = "...";

  buildInputs = [ patchelf ];

  fixupPhase = ''
    patchelf --set-rpath ${libGL}/lib:${mesa}/lib:${wayland}/lib:${libX11}/lib:${libXi}/lib:${libXcursor}/lib:${libXxf86vm}/lib \

The most important part here is the patchelf call where we modify the ELF binaries rpath to contain valid directions to all the listed directories. This should allow it run in both wayland and xorg on NixOS.

This can probably be marked as solved now. If the maintainer wishes to document this somewhere please do. Maybe even just a link to this issue in the readme so people on NixOS don't get stuck and quit trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.