使用 Cargo 选择共享库或静态库
Choosing shared or static library with Cargo
我正在尝试修改 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)。
如何指定我想要构建的库类型,同时仍允许静态构建所述库以包含在可执行文件中?
bin
不是有效的 crate-type
值。有效值为 rlib
、lib
、staticlib
和 dylib
。将板条箱类型更改为
crate-type = ["dylib", "rlib"]
会导致您想要的行为。
["dylib", "bin"]
只发出 rlib 的原因是因为目前有一个 Cargo 错误导致 crate-type
的无效值只产生一个 rlib。我已经提交 pull request 来解决这个问题。
我正在尝试修改 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)。
如何指定我想要构建的库类型,同时仍允许静态构建所述库以包含在可执行文件中?
bin
不是有效的 crate-type
值。有效值为 rlib
、lib
、staticlib
和 dylib
。将板条箱类型更改为
crate-type = ["dylib", "rlib"]
会导致您想要的行为。
["dylib", "bin"]
只发出 rlib 的原因是因为目前有一个 Cargo 错误导致 crate-type
的无效值只产生一个 rlib。我已经提交 pull request 来解决这个问题。