生成dll

建立dll项目

cargo new c13dll --lib

修改Carog.toml

[lib]
name = "c13"
crate-type = ["cdylib"]

修改源码

#[no_mangle]
pub extern fn hello_rust(){
    println!("Hello rust dll!");
}

添加交叉构建

rustup target list
rustup target add i686-pc-windows-msvc

生成dll

cargo build --release --target=i686-pc-windows-msvc

使用Python调用dll

import time
from ctypes import cdll

lib = cdll.LoadLibrary("target/i686-pc-windows-msvc/release/c13.dll")

lib.hello_rust()

相关内容

编辑 | 历史 最近由「jilili」在 2021-05-09 00:56:00 修改