Search code examples
linuxsdl-2rust-cargo

Linking error for SDL2 on linux while building with cargo


I am trying to build a project using cargo and this is the following error I get

  = note: /usr/bin/ld: /home/probot/dappicom/emulator/target/debug/deps/libsdl2-e3367154734f8b05.rlib(sdl2-e3367154734f8b05.sdl2.6bee403e1d2a37b8-cgu.07.rcgu.o): in function `sdl2::url::open_url':
          /home/probot/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl2-0.35.2/src/sdl2/url.rs:65: undefined reference to `SDL_OpenURL'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `tetanes` (bin "tetanes") due to 1 previous error

I tried the solution given here same error but it did not work.

I changed the Library Path according to this solution error but on macOSand it did not work either.

EXPECTED:

successful cargo build.

What did i do

these are the commands I ran .

sudo apt-get update
sudo apt-get install libsdl2-mixer-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev

echo 'export LIBRARY_PATH="$LIBRARY_PATH/usr/local/lib"' \>\> \~/.bash_profile
source \~/.bash_profile

Solution

  • updating sdl2 version to 2.0.14 or above may resolve the problem check your version by

    sdl2-config --version

    ALso check your libsdl2 version to be above same.