VMware配置Ubuntu 编写c程序
文章目录
- Vmware配置Ubuntu
- Vim的使用
- Ubuntu配置
- apt-get配置
- 16.04
- 18.04
- 20.04
- 编写程序
- helloworld程序
- 编写简单程序
- (一)Ubuntu下的简单主/子程序
- (二)Windows下编写程序
- Ubuntu系统使用makefile方式编程
Vmware配置Ubuntu
参考该链接
Vim的使用
vim是一款编辑器,基于vi,可以通过按键就能完成文章的书写,有三种使用模式。
模式 | 作用 |
---|---|
命令模式 | 通过输入vi的命令对文件的内容进行处理(复制、删除、移动等),也可以通过按光标键来移动光标 |
编辑模式 | 可以在光标处输入内容 |
命令项模式 | 命令模式下,用户输入冒号后,光标会跳到底行,然后输入命令 |
常用命令
命令 | 作用 |
---|---|
h | 左移光标 |
l | 右移光标 |
k | 上移光标 |
j | 下移光标 |
i | 插入内容 |
l | 第一行插入 |
a | 光标后插入 |
o | 当前行插入新一行 |
x | 删除光标处字符 |
dd | 删除所在行字符 |
X | 删除光标前的一个字符 |
:n1,n2 t n3 | 把n1行到n2行的内容复制到第n3行的下一行 |
:n1,n2 m n3 | 把n1行到n2行的内容移动到第n3行的下一行 |
:w | 保存文件,不退出 |
:q | 不保存,退出 |
:wq/:x /:ZZ | 保存并退出 |
Ubuntu配置
apt-get配置
采用apt-get安装某个软件时,默认官方的软件源仓库位于国外,下载速度慢,选择国内镜像软件源仓库,提高安装速度。
(1)首先切换目录:cd /etc/apt,查看/编辑sources.list文件:sudo vi sources.list
可以看到都是国外的软件源
(2)删掉sources.list原本的内容,选择合适的源并配置,这里选择阿里源,不同版本的Ubuntu对应的内容是不同的。
16.04
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
18.04
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
20.04
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
(3)文件内容编辑完毕,保存退出,更新源
sudo apt-get update
编写程序
helloworld程序
(1)打开终端,选择合适的位置,创建helloworld文件,通过vim进行编辑文件。
(2)使用gcc命令编译程序
gcc helloworld.c -o helloworld
gcc常用命令如下表
命令 | 作用 |
---|---|
gcc -E helloworld.c -o helloworld. i | 对helloworld.c 的程序进行预编译 .i做扩展名,生成文本文件 |
gcc -S helloworld.i -o helloworld.s | 进行编译,生成一个汇编语言源程序文件.s做扩展名,编译后是文本文件 |
gcc -c helloworld.s -o helloworld.o | 对helloworld.s进行汇编,生成一个可重定位目标文件 . o作扩展名,汇编后是二进制文件 |
gcc helloworld.o -o helloworld | 将多个可重定位目标文件和标准库函数,printf所在的可重定位目标模块printf.o进行链接,生成可执行目标文件 |
gcc helloworld.c -o helloworld | 从c语言程序直接生成可执行目标文件 |
./helloworld | 执行文件helloworld |
(3)运行helloworld文件 |
./helloworld
编写简单程序
(一)Ubuntu下的简单主/子程序
(1)编写一个main.主程序
vim main.c
编写子程序sub.c
(2)编译main.c程序并运行
(二)Windows下编写程序
这里使用VS2017新建一个空项目,编写main.cpp、sub.cpp、sub.h文件,点击运行,得到结果如图。
Ubuntu系统使用makefile方式编程
一个工程文件中的源文件可能有很多,并且不同的功能、模块等都放在不同的目录中,常规的编译已经不能高效化的处理这样的问题,makefile写好后只需要一个make指令,即可完成makefile文件中所编写的所有指令,从而编译整个工程文件。
main.c内容
sub.h内容
makefile内容
hello:main.c sub2.hgcc main.c sub1.h -o hello
运行结果
VMware配置Ubuntu 编写c程序相关推荐
- win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序
win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序 未安装wsl/wsl2的请参照以下链接自行安装 ...
- 虚拟机VMware和Ubuntu的安装与配置教程(超详细,实验可行)
网上各类教程很多,但总有缺漏的地方.在这里我参考了一个比较详细的教程,并针对我第一次安装时遇到的问题,对该教程进行补充(主要在安装源的部分及其他细节). 文章目录 一.安装虚拟机和Ubuntu 虚拟机 ...
- 【ROS】学习笔记一 ubuntu16.04下vs code配置ros环境并编写helloworld程序
[ROS]ubuntu16.04下vs code配置ros环境并编写helloworld程序 一.vs code下载 1.相关配置要求: (1)系统为ubuntu16.04 (2)已安装好kineti ...
- 用Ubuntu编写第一个C程序并预处理、编译、汇编、链接
本篇文章主要介绍如果在Ubuntu系统中编写C程序并将其一步步处理为可执行程序 机器环境:VMWare虚拟机 Ubuntu18.04,系统中安装了gcc编译器与vim工具 1.首先打开想要存放所编写的 ...
- Windows安装VMware虚拟机+配置Ubuntu的详细步骤以及解决配置过程中报错的问题(完整版)
目录 引言: 过程: 安装VMware虚拟机: 在VMware虚拟机中配置Ubuntu: 在VMware虚拟机中安装Ubuntu: VMware中启动虚拟机时报错问题的解决: 正式开始安装Ubuntu ...
- VMware Workstation 运行出现“由于应用程序配置不正确,应用程序未能启动。重新安装应用程序可能会纠正这个问题”解决方案
From: http://blog.csdn.net/lasig/article/details/5694895 今天安装完VMware Workstation 6.5.2之后在运行时,遇到" ...
- Ubuntu下使用AMD APP编写OpenCL程序
对于Ubuntu或其近亲(Lubuntu.Kubuntu.Mint等)编写OpenCL程序也不会太难.由于本例用的是AMD APP SDK,因此需要AMD的GPU以及相关驱动.首先,去AMD官网下载G ...
- 基于Ubuntu(x86)系统和STM32(Keil)编写C程序分别进行编程、验证
文章目录 实验内容 一.基本概念 (一).全局变量 (二).局部变量 (三).堆和栈 二.编程验证 (一).基于Ubuntu用Linux系统编写C程序 (二).基于STM32用Keil编写C程序 三. ...
- Ubuntu 下编写C程序
Ubuntu 下编写C程序 一.编写C程序 二.编译C程序 三.make工具和Makefile文件 一.编写C程序 使用VIM编辑器编写程序,也可以使用vscode. 1.1.设置vim编辑器 设置v ...
最新文章
- VTK:地形抽取用法实战
- org.apache.maven.archiver.MavenArchiver.getManifest错误
- fillrect不填充被覆盖的区域 mfc_quot;条带覆盖quot;猜想的中二证明:quot;球面条线覆盖或点覆盖quot;积分π...
- 电脑安装了mysql,但找不到mysql服务
- 吹气球问题的C语言编程,C语言怎样给一个数组中的数从大到小排序
- pythoninit作用_简介Python中的__init__的作用
- canvas drawImage方法不显示图片的解决方案
- 递推算法之平面分割问题总结
- Nginx+Tomcat关于Session的管理
- 外卖点餐系统源码|餐饮点餐源码开发
- Eclipse中使用SVN教程
- 数学:AI和大数据的基础
- [音乐]阿桑的《叶子》
- 网站使用微信登录接口,所踩的坑...
- redis哨兵模式(docker)
- 软件测试之 loadrunner12.0.2 汉化教程
- eclipse选择java版本_Eclipse 版本选择
- 万字长文分享,新手小白如何自学Java(方法+步骤)
- 基于逻辑回归的癌症分类预测-良/恶性乳腺癌肿瘤预测
- 别贩卖焦虑了,人工智能永远无法取代你