1
votes

I have problems installing the sld2 crate and building a simple project with it.

I am trying to use the crates bundled feature in order to automatically install the SDL2 library and link it properly.

"Bundled" Feature

Since 0.31, this crate supports a feature named "bundled" which downloads SDL2 from source, compiles it and links it automatically. While this should work for any architecture, you will need a C compiler (like gcc, clang, or MS's own compiler) to use this feature properly.

In Cargo.toml I have the following lines to use the bundled feature:

[dependencies.sdl2]
version = "0.33.0"
features = ["bundled","static-link"]

However, when building a simple hello world program with sdl2 crate included:

   Compiling sdl2-sys v0.33.0
error: failed to run custom build command for `sdl2-sys v0.33.0`

Caused by:
  process didn't exit successfully: `D:\3DRendering\3DRendering\rendering\target\debug\build\sdl2-sys-d17fba1aeb343efc\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at '
no valid generator found for GNU toolchain; MSYS or MinGW must be installed

build script failed, must exit now', C:\Users\Fabian\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.42\src\lib.rs:861:5
stack backtrace:
   0: backtrace::backtrace::dbghelp::trace
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/dbghelp.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src\libstd\sys_common/backtrace.rs:84
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src\libstd\sys_common/backtrace.rs:61
   4: core::fmt::write
             at src\libcore\fmt/mod.rs:1025
   5: std::io::Write::write_fmt
             at src\libstd\io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src\libstd\sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src\libstd\sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src\libstd/panicking.rs:193
   9: std::panicking::default_hook
             at src\libstd/panicking.rs:210
  10: std::panicking::rust_panic_with_hook
             at src\libstd/panicking.rs:471
  11: rust_begin_unwind
             at src\libstd/panicking.rs:375
  12: std::panicking::begin_panic_fmt
             at src\libstd/panicking.rs:326
  13: cmake::fail
             at C:\Users\Fabian\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.42\src/lib.rs:861
  14: cmake::Config::build
             at C:\Users\Fabian\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.42\src/lib.rs:400
  15: build_script_build::compile_sdl2
             at .\build.rs:256
  16: build_script_build::main
             at .\build.rs:462
  17: std::rt::lang_start::{{closure}}
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libstd/rt.rs:67
  18: std::rt::lang_start_internal::{{closure}}
             at src\libstd/rt.rs:52
  19: std::panicking::try::do_call
             at src\libstd/panicking.rs:292
  20: __rust_maybe_catch_panic
             at src\libpanic_unwind/lib.rs:78
  21: std::panicking::try
             at src\libstd/panicking.rs:270
  22: std::panic::catch_unwind
             at src\libstd/panic.rs:394
  23: std::rt::lang_start_internal
             at src\libstd/rt.rs:51
  24: std::rt::lang_start
             at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8\src\libstd/rt.rs:67
  25: main
  26: _tmainCRTStartup
  27: mainCRTStartup
  28: unit_addrs_search
  29: unit_addrs_search
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I am on Windows 7, have the latest rust version, MSYS and CMake installed:

C:\Users\Fabian>rustup show
Default host: x86_64-pc-windows-gnu
rustup home:  C:\Users\Fabian\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-gnu (default)
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-gnu

installed targets for active toolchain
--------------------------------------

x86_64-pc-windows-gnu
x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-gnu (default)
rustc 1.41.0 (5e1a79984 2020-01-27)

C:\Users\Fabian>gcc --version
gcc (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\Users\Fabian>cmake --version
cmake version 3.17.0-rc1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Can someone point out the issue(s) to me?

1
Try running cargo from inside an MSYS console, not a standard windows console. - Jmb
@Jmb Same error still occurs - Fabian v.d.W
According to the source code for the cmake crate, this error occurs when neither make nor mingw32-make are found. Do you have either? - Jmb
@Jmb I have neither of those, but also don't seem to understand how I can get them, because I should have the necessary stuff installed, right? - Fabian v.d.W
In msys, I installed mingw32-make, and now I get a few steps further in compiling... Now I get a massive error message, and in the end: = note: ld: cannot find -limm32 ld: cannot find -lversion ld: cannot find -ldinput8 ld: cannot find -ldxguid - Fabian v.d.W

1 Answers

0
votes

Found a way to compile:

Rust comes with a bundled gcc.exe for linking. This gcc is unable to compile C-programs - which is however needed for compilation of above library. This is why I downloaded MSYS to get a full fledged gcc. What I was missing was the mingw32-make command, and that the bundled gcc.exe and ld.exe have to be deleted in order for executables not to get mixed.