【问题标题】:"macro undefined" error while compiling hyper 0.9.17编译超 0.9.17 时出现“宏未定义”错误
【发布时间】:2017-01-28 21:59:53
【问题描述】:

我正在尝试使用 this source as a tutorial 使用 Iron 构建 Web 服务,但在编译 hyper 时出现错误:

Compiling hyper v0.9.17
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:62:23: 62:30 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:62                 qitem(langtag!(en;;;US)),
                                                                                                                                 ^~~~~~~
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:63:34: 63:41 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:63                 QualityItem::new(langtag!(en), Quality(500)),
                                                                                                                                            ^~~~~~~
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:64:23: 64:30 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:64                 qitem(langtag!(fr)),
                                                                                                                                 ^~~~~~~

我正在使用的版本:

  • 货物 0.8.0(建于 2016-03-22)
  • rustc 1.7.0

Cargo.toml

[package]
name = "hello"
version = "0.1.0"
authors = ["root"]

[dependencies]
language-tags = "0.2.2"
iron = "0.4.0"

main.rs:

extern crate iron;

use iron::prelude::*;
use iron::status;
use iron::mime::Mime;

fn main() {
  Iron::new(|_: &mut Request| {
  let content_type = "application/json".parse::<Mime>().unwrap();

  Ok(Response::with((content_type, status::Ok, "{ respone: \"Hello world!\" }")))
 }).http("localhost:3009").unwrap();
}

我只在 Cargo.toml 中添加了语言标签,因为我认为它可以解决我的问题。未进行其他更改。

【问题讨论】:

  • 为什么选择使用 Rust 1.7?此时大约 11 个月大。
  • 感谢@Shepmaster。确实是版本问题。

标签: rust rust-cargo iron hyper


【解决方案1】:

老版本的 Rust 导致了这个问题。今天的稳定版 Rust 是 1.14.0,但在我的 Digital Ocean VM 上,预装了 Rust 1.7。即使运行官方安装程序后,版本仍然是 1.7:

curl https://sh.rustup.rs -sSf | sh

安装后提示:

欢迎来到 Rust!

这将下载并安装 Rust 的官方编译器 编程语言及其包管理器 Cargo。

它将cargo、rustc、rustup等命令添加到Cargo的bin 目录,位于:

/root/.cargo/bin

然后,此路径将添加到您的 PATH 环境变量中 修改配置文件位于:

/root/.profile

我使用不使用 ~/.profile 的 zsh。所以PATH 环境变量没有为我改变,因此命令cargo run 指向/usr/bin/cargo 中预装的旧版本,而不是~/.cargo/bin

您可以使用命令which cargowhich rustc 找到可执行文件的位置。

解决方案是使用~/.cargo/bin/cargo run。对于 zsh,您还可以通过添加

将文件夹 ~/.cargo/bin 添加到您的 PATH 环境变量中
export PATH="~/.cargo/bin:$PATH"

到你的 .zshrc

【讨论】:

  • 我很确定您是否继续阅读安装文本,you would have seen下次您登录时,这将自动完成。 要配置您当前的 shell,请运行 source {cargo_home}/env
猜你喜欢
  • 2013-08-01
  • 2017-06-23
  • 1970-01-01
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多