Rust是否具有dlopen等效项 [英] Does Rust have a dlopen equivalent
问题描述
Rust是否有办法使程序可插入.在C语言中,我创建的插件是使用dlopen加载的.so文件. Rust是否提供本机做同样的事情?
Does Rust have a way to make a program pluggable. In C the plugins I create are .so files that I load with dlopen. Does Rust provide a native way of doing the same thing?
推荐答案
libloading .除此之外,我知道三种不同的选择:
The Rust FAQ officially endorses libloading. Beyond that, there are three different options I know of:
- 使用 shared_library板条箱
- 使用 dylib板条箱.
- 使用
std::dynamic_lib
,即
- Use the shared_library crate
- Use the dylib crate.
- Use
std::dynamic_lib
, which is deprecated since Rust 1.5. (These docs are no longer available in version 1.32; it's likely the feature has been dropped altogether by now.)
我还没有尝试过这些方法,所以我不能真正说出哪个是最佳选择,或者不同变体的优缺点.我强烈建议至少使用std::dynamic_lib
反对,因为它已被弃用,并且将来可能会被私有化.
I haven't tried any of these, so I cannot really say which is best or what the pros/cons are for the different variants. I'd strongly advise against using std::dynamic_lib
at least, given that it's deprecated and will likely be made private at some point in the future.
这篇关于Rust是否具有dlopen等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!