Unable to compile glium example

I'm trying to get one of the glium examples (glium/tutorial-01.rs at master · glium/glium · GitHub) to compile, but it tells me it can't resolve a variable in the glutin package.
I shortened the example a bit, and I put glium = "*" in my dependencies as the project page says, and I've even tried manually putting glutin as a dependency (even though glium includes its own, as far as I can tell). Not sure what else to try because I'm new to Rust.

Here is my source file:

extern crate glium;

fn main() {
    #[allow(unused_imports)]
    use glium::{glutin, Surface};

    let event_loop = glutin::event_loop::EventLoop::new();
    let wb = glutin::window::WindowBuilder::new();
    let cb = glutin::ContextBuilder::new();
    let display = glium::Display::new(wb, cb, &event_loop).unwrap();
}

And the error message I get when building from the command line:

>cargo build
error[E0433]: failed to resolve: could not find `event_loop` in `glutin`
 --> src\main.rs:7:30
  |
7 |     let event_loop = glutin::event_loop::EventLoop::new();
  |                              ^^^^^^^^^^ could not find `event_loop` in `glut
in`

error[E0433]: failed to resolve: could not find `window` in `glutin`
 --> src\main.rs:8:22
  |
8 |     let wb = glutin::window::WindowBuilder::new();
  |                      ^^^^^^ could not find `window` in `glutin`

error: aborting due to 2 previous errors

The examples on the master branch correspond to the latest alpha version of Glutin, and I think using a * dependency won't give you unstable versions. Does changing glutin = "*" to glutin = "0.26.0-alpha3" fix the issue?

yes, changing the dependency to glium = "0.26.0-alpha3" seems to have fixed the problem. I should have thought something was up when they wanted me to use an asterisk instead of a specific version, but I didn't really understand why they wanted me to do that.

thank you!

Whoops, got my 'Rust OpenGL libraries beginning with G' mixed up :sweat_smile:

To give you some context on why there's an alpha version - Winit (the Rust windowing library) is making some fairly large changes to their event loop in the next version, and so they've released an alpha version for people to test out. Glutin (which bundles together Winit with tools for creating an OpenGL context) and Glium (which uses Glutin under the hood) have subsequently followed suit and released alpha versions which pull in the new Winit API.

Personally, I'd recommend never using asterisk dependencies, as it makes it unclear which version you're actually going to get.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.