rust - 如何使用 Rust 和 Amethyst 运行可执行文件
问题描述
所以我遵循了 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)
我应该提供任何想法或更多信息吗?
解决方案
您的主函数调用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
手动设置,然后您应该能够直接执行您的二进制文件。
推荐阅读
- python - “AttributeError:'SelectorList'对象没有属性'get'”在Scrapy Cloud中
- java - Springboot 将日期保存到数据库 1 天休息
- angular - Angular 的 Service Worker 阻止调用 API
- data-visualization - 鼠标悬停在数据点上时更改 MarkerImage 并在离开数据点时更改回
- .htaccess - Htaccess 重定向到 https 同时有来自 vue-router 的另一个条件
- javascript - 测试所有数组元素是否都是数字的因数 - 在 for 循环内返回
- javascript - 安装 npm 包 'kurento-client' 时出错(BufferUtil ~ node-gyp rebuild)
- python - 在会话中存储篮子或购物项目是一种好习惯吗?(姜戈)
- android - 全屏活动力调整平移
- c# - 在 Botframework V4 C# 中调度 LUIS 和 QnA Maker