使用SDL2板条箱运行和构建程序的问题

问题描述 投票:0回答:1

我在安装sld2板条箱并使用它构建一个简单项目时遇到问题。

我正在尝试使用包装箱捆绑功能,以便自动安装SDL2库并正确链接。

"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.

在Cargo.toml中,我有以下几行使用捆绑功能:

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

但是,当使用sdl2板条箱构建简单的hello world程序时:

   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.

我在Windows 7上,具有最新的rust版本,已安装MSYS和CMake:

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).

有人可以向我指出问题吗?

windows rust installation sdl-2
1个回答
0
投票

找到了一种编译方式:

Rust附带了用于链接的捆绑gcc.exe。该gcc无法编译C程序-但是,上述库的编译需要C程序。这就是为什么我下载MSYS以获得完整的gcc的原因。我所缺少的是mingw32-make命令,必须删除捆绑的gcc.exe和ld.exe,以使可执行文件不会混淆。

© www.soinside.com 2019 - 2024. All rights reserved.