Editor's note: This question was asked before Rust 1.0 was released and the syntax, error messages, and even how crates are bundled have changed since then.
我写了一个 Rust 示例程序。 代码是这样的:
use std;
import std::io;
fn main() {
io::println("hello world");
}
我尝试编译它,但 rustc 编译告诉我一些错误消息。
hello.rc:4:0: 4:2 error: expected crate directive
hello.rc:4 fn main() {
^~
我的 rustc 版本是
macmatoMacBook-Air:test kula$ rustc -v
rustc 0.1.1 (a0f0a70 2012-03-10 00:35:02 -0800)
host: x86_64-apple-darwin
我的操作系统是 mac osx 10.7
有人知道怎么回事吗?我认为我的 Rust 代码没有问题。
最佳答案
编译器试图变得聪明,并且对 .rs(源)和 .rc(crate)文件表现不同。
使用 .rs 文件扩展名再试一次! :)
关于rust - "expected crate directive"使用rust 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9645595/