“仓位目标必须可用于'货运运行'" [英] "a bin target must be available for 'cargo run'"
问题描述
在Intellij IDEA 2017中构建新的Rust来自其他来源的项目"时,我无法通过其UI运行该项目.
While building a new Rust "Project from other sources", in Intellij IDEA 2017, I was unable to run the project through its UI.
C:/Users/sjsui/.cargo/bin/cargo.exe运行错误:bin目标必须是 适用于
cargo run
C:/Users/sjsui/.cargo/bin/cargo.exe run error: a bin target must be available for
cargo run
进程退出代码为101
Process finished with exit code 101
我注意到我的构建配置没有提供--bin目标,所以我将路径放置到projects目标文件夹.结果相同.
I noticed that no --bin target was provided by my build configuration so I placed the path to the projects target folder; same result.
C:/Users/sjsui/.cargo/bin/cargo.exe运行--bin C:\ Users \ sjsui \ exercism \ rust \ hello-world \ target \ debug 错误:没有名为
C:\Users\sjsui\exercism\rust\hello-world\target\debug
C:/Users/sjsui/.cargo/bin/cargo.exe run --bin C:\Users\sjsui\exercism\rust\hello-world\target\debug error: no bin target named
C:\Users\sjsui\exercism\rust\hello-world\target\debug
我尝试通过Cargo命令行界面创建一个新的Rust项目,并在运行它时收到此错误:
I tried creating a fresh Rust project through the Cargo command line interface, and received this error when running it:
错误:无法执行链接器
link.exe
:系统找不到指定的文件. (操作系统错误2) 注意:msvc目标取决于msvc链接器,但是link.exe
是 找不到
error: could not exec the linker
link.exe
: The system cannot find the file specified. (os error 2) note: the msvc targets depend on the msvc linker butlink.exe
was not found
注意:请确保VS 2013或VS 2015已随 Visual C ++选项
note: please ensure that VS 2013 or VS 2015 was installed with the Visual C++ option
很明显,我必须安装Visual C ++构建工具2017,并且正在安装中.这些错误是相关的还是其他问题?
Evidently I must install Visual C++ build tools 2017 and am in the process of doing so. Are these errors related, or different issues?
推荐答案
默认情况下,Cargo会将文件src/main.rs
视为该软件包的主要二进制目标.如果此文件不存在,并且在Cargo.toml
中没有定义其他二进制目标,则将收到此错误.
By default, Cargo will consider the file src/main.rs
to be the main binary target for the package. If this file doesn't exist, and there are no other binary targets defined in Cargo.toml
, you'll get this error.
根据文档,当您在IntelliJ IDEA,您可以选择使用二进制(应用程序)模板.这应该为您提供src/main.rs
而不是src/lib.rs
(这是库目标的默认根文件).在命令行上使用Cargo,您还可以使用
According to the documentation, when you create a Rust project in IntelliJ IDEA, you get an option to Use a binary (application) template. This should give you a src/main.rs
instead of a src/lib.rs
(which is the default root file for a library target). Using Cargo on the command line, you can also create an application package with cargo new hello
.
Cargo默认为
--bin
以生成二进制程序.要创建一个库,我们将传递--lib
.
Cargo defaults to
--bin
to make a binary program. To make a library, we'd pass--lib
.
在cargo run
命令上使用--bin
时,该参数引用 [[bin]]
部分,或遵循模式src/bin/*.rs
的文件(参数替换*
)在Cargo.toml
中.例如,cargo run --bin foo
将使用Cargo.toml
中的name = "foo"
编译并运行src/bin/foo.rs
或[[bin]]
部分.
When you use --bin
on the cargo run
command, the argument refers to one of the [[bin]]
sections in Cargo.toml
, or files following the pattern src/bin/*.rs
(the argument replaces the *
) if there are no [[bin]]
sections in Cargo.toml
. For example, cargo run --bin foo
will either compile and run src/bin/foo.rs
or the [[bin]]
section with name = "foo"
in Cargo.toml
.
这篇关于“仓位目标必须可用于'货运运行'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!