A slight problem with SDL2 and Rust
This is on Ubuntu 24.04 LTS. I’ve installed the dev versions of SDL2, including images and TTF. You can read how to install them in this tutorial.
Once that’s done you add them to the rust project with commands like this
cargo add sdl2
You can see these instruction in the relevant crates pages. For instance SDL2 crate, SDL2 Image and SDL2 TTF.
So far so good. The cargo add added the crates into cargo.toml as expected but when I compiled it. Not a compile error as such but a version of dll hell.
The text in that image says:
Updating crates.io index error: failed to select a version for `sdl2-sys`. ... required by package `sdl2_image v0.25.0` ... which satisfies dependency `sdl2_image = "^0.25.0"` of package `sdl1 v0.1.0 (/home/david/rust/sdl1)` versions that meet the requirements `^0.25.0` are: 0.25.0 the package `sdl2-sys` links to the native library `SDL2`, but it conflicts with a previous package which links to `SDL2` as well: package `sdl2-sys v0.37.0` ... which satisfies dependency `sdl2-sys = "^0.37.0"` of package `sdl1 v0.1.0 (/home/david/rust/sdl1)` Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "SDL2"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links. failed to select a version for `sdl2-sys` which could resolve this conflict
The problem appears to be a clash between sdl-sys and sdl2-ttf or sdl2-image. If anyone knows a fix…
I’m aware that C is notorious for unexpected behaviour (UB). Let me describe this bug:
There’s nothing worse than a program halting with a simple “Segmentation fault” and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong.




When programmers have to explain why it took longer to get something working,you don’t often here reasons like this. A simple syntax error error took me an hour to find and fix. Yet it does happen and it happened to me today.
I was interested in seeing what frame rate I got out of it and how much it warmed the PI.