【问题标题】:How to run the executable with Rust and Amethyst如何使用 Rust 和 Amethyst 运行可执行文件
【发布时间】:2020-04-24 13:26:20
【问题描述】:

所以我遵循了 Amethyst Pong 教程,现在正在构建一个小的生命游戏程序。如果我使用cargo run 运行它,它工作正常,但如果我使用cargo build 然后运行

$ .\target\debug\game_of_life.exe

我得到错误:

Error: Error { inner: Inner { source: None, backtrace: None, error: ConfigError(File(Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." })) } }

如果还不清楚我在 Windows 10 上。我还创建了一个空白 rust 项目并尝试运行它的可执行文件,它运行良好:

$ cargo new temp
$ cd temp
$ cargo build
$ .\target\debug\temp.exe
Hello, world!

复制步骤(必须安装 cargo 和 vulkan):

$ cargo install amethyst_tools
$ amethyst new temp
$ cd temp
$ cargo build
$ .\target\debug\temp.exe
Error: Error { inner: Inner { source: None, backtrace: None, error: ConfigError(File(Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." })) } }

请注意:

$ amethyst new temp
$ cd temp
$ cargo run

工作正常

版本:

$ amethyst --version
Amethyst CLI 0.10.0
$ cargo --version
cargo 1.43.0 (3532cf738 2020-03-17)

我应该提供任何想法或更多信息吗?

【问题讨论】:

    标签: rust amethyst


    【解决方案1】:

    您的主函数调用 application_root_dir,它是 Amethyst 的一部分。 application_root_dir 的定义表明它使用CARGO_MANIFEST_DIR 或可执行文件的位置作为根路径(稍后用于查找资产和配置)。当你调用 cargo run 时,它会将 CARGO_MANIFEST_DIR 设置为当前构建的 crate 的 Cargo.toml 的目录,而如果你直接调用二进制文件,CARGO_MANIFEST_DIR 根本不会被设置(所以它会尝试使用 .\target\debug作为查找配置/资产的基本路径)。

    您可以将二进制文件复制到您的Cargo.toml 的位置或手动设置CARGO_MANIFEST_DIR,然后您应该可以直接执行您的二进制文件。

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 2021-05-12
      • 2020-10-12
      • 1970-01-01
      • 2018-08-06
      • 2013-01-13
      • 2012-07-04
      相关资源
      最近更新 更多