gpt4 book ai didi

windows - 使用SDL2 crate 运行和构建程序时出现问题

转载 作者:行者123 更新时间:2023-12-03 11:39:54 24 4
gpt4 key购买 nike

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

我正在尝试使用包装箱 bundle 功能,以便自动安装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中,我有以下几行使用 bundle 功能:
[dependencies.sdl2]
version = "0.33.0"
features = ["bundled","static-link"]

但是,在使用sdl2 crate构建简单的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).

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

最佳答案

找到了一种编译方式:

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

关于windows - 使用SDL2 crate 运行和构建程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60432515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com