Rust-SDL2 / rust-sdl2

SDL2 bindings for Rust
MIT License
2.77k stars 474 forks source link

Could not compile rust project using `image` feature in linux #1443

Closed Supermanuu closed 1 week ago

Supermanuu commented 1 week ago

Distro: Ubuntu 20.04.6 LTS Version: sdl2 = { version = "0.37.0", features = ["image"] } Installed versions through apt:

libsdl2-dev = 2.0.10+dfsg1-3
libsdl2-mixer-dev = 2.0.4+dfsg1-2build1
libsdl2-gfx-dev = 1.0.4+dfsg-3
libsdl2-image-dev = 2.0.5+dfsg1-2
libsdl2-ttf-dev = 2.0.15+dfsg1-1

Compilation error:

...
  = note: /usr/bin/ld: path/target/debug/deps/libsdl2-84220883b23e1bb6.rlib(sdl2-84220883b23e1bb6.sdl2.ee0141da827b756b-cgu.4.rcgu.o): in function `<sdl2::video::WindowContext as core::ops::drop::Drop>::drop':
          path/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl2-0.37.0/src/sdl2/video.rs:559: undefined reference to `SDL_Metal_DestroyView'
          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#rustc-link-lib)
...

I dont know how to get this working... and I have not found anything on the internet...

Could be that the only way to get it working is downloading the libraries by hand?

Thank you!

Supermanuu commented 1 week ago

I have downloaded and executed the image-demo test... so is something about my project...

This is my Cargo.toml file:

[package]
name = "P360-RPIZ-BACK"
version = "0.1.0"
edition = "2021"

[dependencies]
gopro-controller = { git = "https://github.com/Supermanuu/gopro-controller.git", branch = "wifi-connect", version = "0.10.5" }
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.16" }
regex = { version = "1.11.0" }
tonic = "0.12"
tonic-web = "0.12.3"
prost = "0.13"
tower-http = { version = "0.6.1", features = ["cors"] }
thiserror = "1.0.65"
bluer = { version = "0.17.3", features = ["bluetoothd"] }
futures = "0.3.31"
serde = { version = "1.0.213" }
serde_json = { version = "1.0.132" }
chrono = { version = "0.4.38" }
rppal = "0.19.0"
qrc = "0.0.5"
sdl2 = { version = "0.37.0", features = ["image"] }

[build-dependencies]
tonic-build = "0.12"

# For cross compile
[workspace.metadata.cross.target.aarch64-unknown-linux-gnu]
# Install some packages, see <https://github.com/cross-rs/cross/blob/main/docs/custom_images.md#adding-dependencies-to-existing-images>
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH && apt update && apt install -y libdbus-1-dev:$CROSS_DEB_ARCH pkg-config:$CROSS_DEB_ARCH protobuf-compiler:$CROSS_DEB_ARCH libsdl2-dev:$CROSS_DEB_ARCH libsdl2-image-dev:$CROSS_DEB_ARCH libsdl2-mixer-dev:$CROSS_DEB_ARCH",
]

I was compiling it with cargo build and I have a build.rs file:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let proto_file = if std::path::Path::new("/.dockerenv").exists() {
        // Dockerized build has no access to the repo root
        "backend.proto"
    } else {
        "../backend.proto"
    };
    tonic_build::compile_protos(proto_file)?;

    Ok(())
}

Could be that any of the dependencies are not compatible with sdl2?

Cobrand commented 1 week ago

SDL_Metal_DestroyView is a macos specific function that is only compiled when the target is set to macos, so if you are on linux it's logical it's not being found. Other than that I don't have enough info to know what is going on.

Cobrand commented 1 week ago

Actually it's probably related to #1409 , try using the master version of the repo and see if its works?

Supermanuu commented 1 week ago

Yeah, thats right! Adding git master branch solved the problem!

Thank you very much!

I thought that the master branch should be released in crates.io, but is not.