知识卡片
导出ABI与符号名分别控制
extern “C”为Rust定义选择C调用ABI,no_mangle等属性控制外部符号名;两者不是同一个开关。公开符号可加库前缀减少全局冲突。Rust2024要求写成#[unsafe(no_mangle)],提醒维护者保证链接符号契约,不是自动验证名称永不冲突。
版本依据:Edition Guide不安全属性,2026-10-27查阅。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 6. Beyond Standard Rust Invoking Rust from C · 查看原书依据
Invoking Rust from C What counts as “foreign” depends on where you’re standing: if you’re writing an application in C, then it may be a Rust library that’s accessed via a foreign function interface. The basics of exposing a Rust library to C code are similar to the opposite direction: Rust functions that are exposed to C need an extern "C" marker to ensure t
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第6章《Invoking Rust from C》(spine10;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch06.html;u180-ch06-015)。
- 结论依据:原文在“Invoking Rust from C”附近的定义、例子或代码支撑本卡核心说明:extern "C"为Rust定义选择C调用ABI,no_mangle等属性控制外部符号名;两者不是同一个开关。边界按已读前提解释;示例未执行。
- 原始内容:Invoking Rust from C What counts as “foreign” depends on where you’re standing: if you’re writing an application in C, then it may be a Rust library that’s accessed via a foreign function interface. The basics of exposing a Rust library to C code are similar to the opposite direction: Rust functions that are exposed to C need an extern "C" marker to ensure t