Rust SDL2 compilation error

I am learning rust using sdl2 crate "sdl2 - Rust" but during compilation of the demo i am getting error as below, Please any one help me on this.

Blocking waiting for file lock on build directory

Compiling rust_project v0.1.0 (/Users/sds-s.balaji/rustProject)
error: linking with cc failed: exit code: 1
|
= note: "cc" "-m64" "-L" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.1ovmfoe8zuq7w53j.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.26zch8whvldvjcqo.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.297jfxu6982ejfsd.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.2zfwc741mh7sdo0n.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.31m72g6smm49rktv.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.34e6ojxtxrvj5z1d.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.34vwb8suffrvdr6l.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.3ln7ilbybqf09z5v.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.3myhwltn2xd7wtr.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.41u8ib6ni9hfb56m.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.43tpt9r8q51yb5cj.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4h37jnczueolz0ee.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4hz7dl1w9zw9ym76.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4iyqohak1p1k42ud.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4jv8zj08voumwuan.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4pq7bddjc4r28ow5.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4r2r1uxwdnwkoie.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.501uiff8ju5m6dm4.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.55z8rq2f3irimj92.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.58utzaie5h1strst.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.59fvi654kx1rd0sv.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.5d6hnqqrsbjbyqce.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.5eae7d7oc0nmd3ey.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.75z9fhb00xult4l.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.9ovw3lomk4jqhiy.rcgu.o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.r4whwi3j5xsvxh1.rcgu.o" "-o" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3" "/Users/sds-s.balaji/rustProject/target/debug/deps/rust_project-6c869e2929904ae3.4m9e2iwtlveaisv0.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/sds-s.balaji/rustProject/target/debug/deps" "-L" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/sds-s.balaji/rustProject/target/debug/deps/libsdl2-8102600fd3fbb793.rlib" "/Users/sds-s.balaji/rustProject/target/debug/deps/libsdl2_sys-f24d2ced2a98ba60.rlib" "/Users/sds-s.balaji/rustProject/target/debug/deps/libbitflags-9bf2dd559877cc58.rlib" "/Users/sds-s.balaji/rustProject/target/debug/deps/liblazy_static-6bff4de4142b5229.rlib" "/Users/sds-s.balaji/rustProject/target/debug/deps/liblibc-bbaef975a82234c8.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-5aac390c25a3be91.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-8d95e919acff6358.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-b74724130e02bca1.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-0e0d29142d1c9272.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace-f1652c422fbf7fc7.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libbacktrace_sys-3d74ad27c9a94aec.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-1255ec28ac7c09c4.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-8753dbda32b8facf.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-a00fd94477b6f959.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-764e6791ca18d144.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-a494dce1f057654b.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-2c78f494769c69d7.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-47f37590dc106077.rlib" "/Users/sds-s.balaji/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-edfd79f9969978bb.rlib" "-lSDL2" "-lSystem" "-lresolv" "-lc" "-lm"
= note: ld: library not found for -lSDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Blocking waiting for file lock on build directory

This means that some other process is currently doing a build or a check. This could be your IDE doing a "cargo check on save" (VSCode with rust-analyzer will do this, for example)

= note: ld: library not found for -lSDL2

Did you install SDL2 library first? Here are a bunch of instructions for various different platforms here, as well as instructions for using a "bundled" SDL2:

I'm currently using the SDL2 binding for Rust and that works well. And looking at the error message, i agree with previous message : your SDL2 dev maybe is not installed. I recommend to you using the installing of SDL2 library with your package manager if you are on Linux system. And if you want to try a C program to be sure that the SDL2 is really found, you can use this command : gcc -o myprogram myprogram.c `sdl2-config --cflags --libs` (take care to the ` character).

1 Like

Thanks for the quick solution, now it's working. Happy :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.