How to use panic=abort with external dependencies?

For single crate projects, adding these lines to Cargo.toml works as expected.

[profile.release]
panic = "abort"

Then build the project:

cargo build --release

However, on a project which has indirectly used dependencies, I'm getting an error.

    Compiling c_vec v1.0.12
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`

error: aborting due to previous error

Build failed, waiting for other jobs to finish...
error: Could not compile `c_vec`.

The c_vec crate is an indirectly used dependency.

How to use panic=abort on a multi-crate project without conflicts?


Details incase they matter:

  • Rustc 1.12.0
  • Library with issue: lodepng-rust
  • Linux, 64bit

  • Looks like it's because c_vec specifies dylib as one of its library types.

    I filed this as an issue on Github here: https://github.com/rust-lang/cargo/issues/2738

    And got an answer from one of the devs:

    ah unfortunately that's a bad error message but it's because of crate-type = ["dylib", "rlib"] in the c_vec crate. This causes Cargo to pass -C prefer-dynamic which links to the dylib that we ship which is compiled against panic_unwind, meaning the abort mode is indeed invalid (this error is coming from the compiler).

    The fix here would be to remove "dylib" from the c_vec crate.

    Of course, you'd have to fork your own lodepng and c_vec to take care of this.

    链接地址: http://www.djcxy.com/p/36482.html

    上一篇: 设备脱机时,StorageReference.getFile()会崩溃

    下一篇: 如何使用panic =与外部依赖关系中止?