Compiling Crates as a dylib

Hello o/,

I'm working on compiling Rust crates as dynamic libraries (dylib) to perform binary diffing for reverse engineering stripped Rust binaries. However, I'm encountering an issue that I can't resolve.

Here's the situation:

I'm using regex to download the necessary crates. Once downloaded, I modify the Cargo.toml file by adding the following configuration to compile them as dynamic libraries, as suggested in this discussion: What is the difference between dylib and cdylib?

[lib] 
crate-type = ["dylib"]
[profile.release]
panic="abort"

However, when I run cargo build --release with this modified configuration, I receive the following error:

error: `#[panic_handler]` function required, but not found  
warning: `aes` (lib) generated 32 warnings
error: could not compile `aes` (lib) due to 1 previous error; 32 warnings emitted

The solution i've found comes from here, and is to add a bit of code.
A Freestanding Rust Binary | Writing an OS in Rust. This seems to work, but i'm not sure that adding code is a good idea. Moreover, this seems to be for embedded developpement, while i'm targeting x86-64 linux/windows

My question is: Do you have a better idea on how to fix this problem without altering the code?

Are you building a #![no_std] crate? If so try either removing the #![no_std] or you have to add a panic handler.

You can have another crate which depends on your crate which either doesn't use #![no_std] or defines a panic handler. (make sure to add use my_crate_name as _; to ensure that it links against my_crate_name) This other crate can then be compiled as dylib rather than the original crate.

Thank you, it was the problem. On a side note, maybe you'll have the answer, when i do cargo add aes in a project i do'nt have to remove this line ?

Generally that happens when a dependency uses libstd or itself depends on a crate that uses libstd. I think all dependencies of the aes crate are no_std however, so I'm not sure why it works when you include the aes crate though.