6

我正在尝试修改Racer以发出共享库而不是 rlib。

为此,我添加crate-type = ["dylib"][lib]货物清单的部分,然后运行cargo build --lib​​. 这很好用,并且libracer.so被发射了。

不幸的是,现在我无法构建 Racer 二进制文件,它依赖于库的静态版本。跑步cargo build抱怨:

   Compiling racer v1.0.0 (file:///home/georgev/dotfiles/vim/bundle/racer)
error: cannot satisfy dependencies so `std` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `core` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `collections` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rustc_unicode` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `alloc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `libc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rand` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: aborting due to 7 previous errors
Could not compile `racer`.

我将 更改crate-type["dylib", "bin"],这使得编译成功。但是,cargo build --lib将不再发出共享库(仅 rlib)。

如何指定要构建的库类型,同时仍允许静态构建所述库以包含在可执行文件中?

4

1 回答 1

9

bin不是有效值crate-type。有效值为rliblibstaticlibdylib。将箱子类型更改为

crate-type = ["dylib", "rlib"]

会导致你所追求的行为。

只发出一个 rlib 的原因["dylib", "bin"]是因为当前有一个 Cargo 错误导致无效值crate-type只产生一个 rlib。我已经提交了一个拉取请求来解决这个问题。

于 2015-08-17T16:23:30.053 回答