当前位置: 首页 > news >正文

一般网站的建设步骤有哪些长沙网站推广seo

一般网站的建设步骤有哪些,长沙网站推广seo,政府类网站模板,b2b商贸网站提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 ubuntu20.04搭建RUST开发环境并与C语言交互 前言开战一、确认环境版本二、环境搭建三、hello world!四、跟c语言进行交互1.rust调用C静态库2.C调用rust库 总结参考…

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

ubuntu20.04搭建RUST开发环境并与C语言交互

  • 前言
  • 开战
    • 一、确认环境版本
    • 二、环境搭建
    • 三、hello world!
    • 四、跟c语言进行交互
      • 1.rust调用C静态库
      • 2.C调用rust库
  • 总结
  • 参考


前言

开始学习rust,从网上扒资料搭建开发环境。后续再跟OpenHarmony-RISCV结合。


开战

一、确认环境版本

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

二、环境搭建

root@znvhwd:/home/ptg/rust# curl --proto ‘=https’ --tlsv1.2 https://sh.rustup.rs -sSf | sh
curl: (35) OpenSSL SSL_connect: 连接被对方重设 in connection to sh.rustup.rs:443
root@znvhwd:/home/ptg/rust# ls
root@znvhwd:/home/ptg/rust# sudo apt-get install git
正在读取软件包列表… 完成
正在分析软件包的依赖关系树
正在读取状态信息… 完成
git 已经是最新版 (1:2.25.1-1ubuntu3.13)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 31 个软件包未被升级。
root@znvhwd:/home/ptg/rust# curl --proto ‘=https’ --tlsv1.2 https://sh.rustup.rs -sSf | sh
curl: (35) OpenSSL SSL_connect: 连接被对方重设 in connection to sh.rustup.rs:443

获取rustup安装脚本失败,有资料说是没安装git导致,但环境中实际有git。大概率还是本地虚拟机网络的问题。
经排查修改DNS即可:Ubuntu修改DNS的方法

  1. 编辑 /etc/resolv.conf 文件
    sudo vim /etc/resolv.conf
  2. 加入以下代码
    nameserver 114.114.114.114
    nameserver 8.8.8.8

又遇新坑
在这里插入图片描述
不知道啥原因,曲线救国了。
浏览器打开https://sh.rustup.rs,直接下载到rustup-init.sh。然后“./”执行即可。
在这里插入图片描述
多灾多难。。
https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init
再次尝试,下载rustup-init。然后“./”执行。
报错:

error: error decoding response body: operation timed out

解决:

RUSTUP_DIST_SERVER=‘https://mirrors.ustc.edu.cn/rust-static’
RUSTUP_UPDATE_ROOT=‘https://mirrors.ustc.edu.cn/rust-static/rustup’

在这里插入图片描述
终于下完了,引用环境变量(环境变量已经默认写入到~/.bashrc)

source ~/.bashrc

试用:cargo
在这里插入图片描述
搞定。

三、hello world!

root@znvhwd:/home/ptg/rust# cargo new myos
Creating binary (application) myos package
note: see more Cargo.toml keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
root@znvhwd:/home/ptg/rust# ls
main.rs myos rustup-init rustup-init.sh
root@znvhwd:/home/ptg/rust# cd myos
root@znvhwd:/home/ptg/rust/myos# cargo run
Compiling myos v0.1.0 (/home/ptg/rust/myos)
Finished dev profile [unoptimized + debuginfo] target(s) in 0.20s
Running target/debug/myos
Hello, world!
root@znvhwd:/home/ptg/rust/myos# ls
Cargo.lock Cargo.toml src target
root@znvhwd:/home/ptg/rust/myos#
root@znvhwd:/home/ptg/rust/myos#
root@znvhwd:/home/ptg/rust/myos# cd src/
root@znvhwd:/home/ptg/rust/myos/src# ls
main.rs
root@znvhwd:/home/ptg/rust/myos/src# cat main.rs
fn main() {
println!(“Hello, world!”);
}

执行上面的命令应该是直接下载了一个git项目。

四、跟c语言进行交互

在Rust中调用C语言的代码需要以下几个步骤:

  1. 编写或获得C语言的代码。
  2. 创建Rust的外部函数接口(FFI)。
  3. 使用Rust的unsafe块调用C函数。

1.rust调用C静态库

参考 Rust调用C程序的实现步骤
编译得到一个C语言的静态库

/*swap.c*/
#include "stdint.h"int swap(int32_t* a, int32_t* b)
{int32_t tmp = *a;*a = *b;*b = tmp;return 0;
}

gcc -c swap.c
ar rcs libswap.a swap.o

在Rust中创建一个外部函数接口来使用这个库。
Cargo.toml文件中添加一个build.rs脚本以及libc依赖:

[package]
name = "myos"
version = "0.1.0"
edition = "2021"
build = "build.rs"[dependencies]
libc = "0.2"[build-dependencies]
cc = "1.0"

在build.rs脚本(笔者将其放在了项目根目录下)中告诉cargo如何构建C库

/*build.rs*/
extern crate cc;fn main()
{cc::Build::new().file("swap.c").compile("libswap.a");
}

创建Rust的外部函数接口,可以
修改hello rust的main.rs

/*main.rs*/
extern crate libc;extern "C"
{fn swap(a: *mut i32, b: *mut i32);
}fn main()
{println!!!!!!!!!!!("hello,rust!");let mut x = 5;let mut y = 10;unsafe{swap(&mut x as *mut i32, &mut y as *mut i32);}println!("x: {}, y: {}", x, y);
}

在这里插入图片描述
报错:

warning: spurious network error (3 tries remaining): [35] SSL connecterror (Recv failure: Connection reset by peer)
warning: spuriousnetwork error (3 tries remaining): [28] Timeout was reached

应该还是网络的问题。。
尝试wget 对应文件,SSL问题。
查了半天终于找到了解决方法

root@znvhwd:/home/ptg/rust/myos# cd ~/.cargo
root@znvhwd:~/.cargo# ls
bin config env registry
root@znvhwd:~/.cargo# cat config
[http]
check-revoke = false
root@znvhwd:~/.cargo# root@znvhwd:/home/ptg/rust/myos# cd ~/.cargo
root@znvhwd:~/.cargo# ls
bin config env registry
root@znvhwd:~/.cargo# cat config
[http]
check-revoke = false
root@znvhwd:~/.cargo# vim config

修改配置文件,应该是换了源

[http]
check-revoke = false
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

在这里插入图片描述
终于搞定了。

2.C调用rust库

参考 C语言和Rust语言的互相调用(1)(C调用Rust)

总结

没啥 ,找资料照做,遇到问题解决问题即可。

参考

https://zhaoseaside.blog.csdn.net/article/details/134484039
https://blog.csdn.net/fittec/article/details/137204059
https://zhuanlan.zhihu.com/p/687515644
https://www.jb51.net/program/307143aaq.htm
https://blog.csdn.net/phthon1997/article/details/126469708

http://www.hkea.cn/news/457100/

相关文章:

  • 企业网站开发信息搜索大全浏览器
  • 做虚拟货币交易网站域名注册平台有哪些
  • 企业网站首页的实现专业的网页制作公司
  • 动态网站建设教程宝鸡seo排名
  • 做外贸b2b免费网站优化推广网站排名
  • 丹徒网站建设价格香港服务器
  • 宿迁哪里有做网站开发的信息流广告案例
  • 电脑网页无法访问如何解决北京seo地址
  • 直销网站系统制作价格java培训机构
  • dw软件个人简历网站怎么做百度导航下载2022最新版官网
  • 成都官方网站建设泉州seo外包
  • 矿山建设网站天津网络推广seo
  • 国内优秀的响应式网站深圳专业seo外包
  • 重庆装修价格c盘优化大师
  • 银行网站 设计方案外包优化网站
  • 做网站是学什么专业软件外包企业排名
  • wordpress商城 中文站百度站长平台网址
  • 建手机网站的软件有哪些南宁百度seo价格
  • 做网站私活长沙网络营销公司
  • 网站建设公司 广告法被处罚沧州网络推广外包公司
  • 电商网站 开发成本惠州seo外包服务
  • 佛山做网站建设价格百度网盘官方下载
  • 网上购物商城网站建设个人免费域名注册网站
  • 成都学网站建设电子营销主要做什么
  • 织梦cms通用蓝白简介大气企业网站环保科技公司源码网络推广员招聘
  • 网站后台怎么添加图片视频app推广
  • 网站秒收录怎么做的经典软文案例和扶贫农产品软文
  • 珠海疫情最新情况厦门搜索引擎优化
  • 中国菲律宾历史战绩网站关键词优化工具
  • 西宁网站建设最好的公司哪家好优秀网站设计案例