使用 Rust 进行嵌入式研发
发布时间:2021-10-27 14:10:44 所属栏目:语言 来源:互联网
导读:现在你可以对你的 Rust 库进行调用了。 1、把生成的 sum.h 和 sum.a 文件放到 rt-thread/bsp/qemu-vexpress-a9/applications 目录下。 2、修改 SConscript 文件并添加一个静态库: from building import * cwd = GetCurrentDir() src = Glob(*.c) + Glob(*.c
现在你可以对你的 Rust 库进行调用了。
1、把生成的 sum.h 和 sum.a 文件放到 rt-thread/bsp/qemu-vexpress-a9/applications 目录下。
2、修改 SConscript 文件并添加一个静态库:
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
LIBS = ["libsum.a"]
LIBPATH = [GetCurrentDir()]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH, LIBS = LIBS, LIBPATH = LIBPATH)
Return('group')
3、在主函数中调用 sum 函数,得到返回值,并 printf 该值:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <rtthread.h>
#include "sum.h"
int main(void)
{
int32_t tmp;
tmp = sum(1, 2);
printf("call rust sum(1, 2) = %dn", tmp);
return 0;
}
4、在 RT-Thread Env 环境中,使用 scons 来编译项目并运行:
$ scons -j6
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
[...]
scons: done building targets.
$ qemu.sh
| /
- RT - Thread Operating System
/ | 4.0.4 build Jul 28 2021
2006 - 2021 Copyright by rt-thread team
lwIP-2.1.2 initialized!
[...]
call rust sum(1, 2) = 3
(编辑:孝感站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |