Updated 'src/advanced_features/unsafe.md'.

This commit is contained in:
Hector PENG
2026-04-23 09:12:15 +08:00
parent 7e0e246c3e
commit 631e084c7c
5 changed files with 94 additions and 6 deletions

View File

@@ -0,0 +1,10 @@
[package]
name = "my_rust_lib"
version = "0.1.0"
edition = "2024"
[lib]
name = "my_rust_lib"
crate-type = ["cdylib"]
[dependencies]

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
extern void call_from_c();
int main () {
call_from_c();
return 0;
}

BIN
projects/my_rust_lib/my_app Executable file

Binary file not shown.

View File

@@ -0,0 +1,5 @@
#[unsafe(no_mangle)]
pub extern "C" fn call_from_c() {
println!("刚刚从 C 调用了 Rust 函数!");
}