首先要在目标机(OrangePI)上安装samba软件:
1:sudo apt-get update
2.sudo apt-get install samba samba-common-bin -y
3.安装完成后修改配置文件:
sudo gedit /etc/samba/smb.conf
在文件末尾添加:
[root]
workgroup = root
security = root
netbios name = root
comment = root
path = /
browsable = yes
writeable = yes
read only = no
保存退出:
4.增加samba用户:sudo smbpasswd -a root输入两次密码。
5.重启服务 :sudo /etc/init.d/samba restart
6.如果主机使用Linux,需要安装smbclient安装:
sudo apt-get install smbclient
7 查看目录的所有共享目录
smbclient -L 10.0.0.11 # 10.0.0.11是samba服务器IP
8连接共享目录
smbclient //10.0.0.11/root # IP地址后接共享目录
9挂载共享目录到本地:
mount -t cifs -o username=xxx,password=xxx //10.0.0.11/root /home/zhangchengfei/tmp# 后面的是挂载目录
10.在主机安装rust:
$ curl https://sh.rustup.rs -sSf | sh
11.安装交叉编译器:
$ sudo apt-get install gcc-arm-linux-gnueabihf
12添加编译器到rust 中
$ rustup target add armv7-unknown-linux-gnueabihf
13添加环境变量
$ mkdir -p ~/.cargo $ cat >>~/.cargo/config <<EOF > [target.armv7-unknown-linux-gnueabihf] > linker = "arm-linux-gnueabihf-gcc" > EOF
14 安装PYTHON支持:
sudo apt install python3-dev python-dev
15创建文件并进行交叉编译:
$ cargo new --bin hello $ cd hello/src
$ del main.rs
$gedit lib.rs
use pyo3::prelude::*;
//use std::f32::consts::PI;
use pyo3::wrap_pyfunction;
#[pyfunction]
fn hello() -> PyResult<()> {
println!("Hello,Rust!");
Ok(())
}
#[pymodule]
fn r2p(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!( hello ))?;
Ok(())
} $ cargo build --target=armv7-unknown-linux-gnueabihf 之后会在target/armv7-unknown-linux-gnueabihf 目录下生成libr2p.so
16 把文件名改成模块名:r2p.so,并把文件复制到目标机器上运行即可.
到此已经顺利在OrangePI上运行Rust Python!