文章目录

  • 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程序相关推荐

  1. win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序

    win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序 未安装wsl/wsl2的请参照以下链接自行安装 ...

  2. 虚拟机VMware和Ubuntu的安装与配置教程(超详细,实验可行)

    网上各类教程很多,但总有缺漏的地方.在这里我参考了一个比较详细的教程,并针对我第一次安装时遇到的问题,对该教程进行补充(主要在安装源的部分及其他细节). 文章目录 一.安装虚拟机和Ubuntu 虚拟机 ...

  3. 【ROS】学习笔记一 ubuntu16.04下vs code配置ros环境并编写helloworld程序

    [ROS]ubuntu16.04下vs code配置ros环境并编写helloworld程序 一.vs code下载 1.相关配置要求: (1)系统为ubuntu16.04 (2)已安装好kineti ...

  4. 用Ubuntu编写第一个C程序并预处理、编译、汇编、链接

    本篇文章主要介绍如果在Ubuntu系统中编写C程序并将其一步步处理为可执行程序 机器环境:VMWare虚拟机 Ubuntu18.04,系统中安装了gcc编译器与vim工具 1.首先打开想要存放所编写的 ...

  5. Windows安装VMware虚拟机+配置Ubuntu的详细步骤以及解决配置过程中报错的问题(完整版)

    目录 引言: 过程: 安装VMware虚拟机: 在VMware虚拟机中配置Ubuntu: 在VMware虚拟机中安装Ubuntu: VMware中启动虚拟机时报错问题的解决: 正式开始安装Ubuntu ...

  6. VMware Workstation 运行出现“由于应用程序配置不正确,应用程序未能启动。重新安装应用程序可能会纠正这个问题”解决方案

    From: http://blog.csdn.net/lasig/article/details/5694895 今天安装完VMware Workstation 6.5.2之后在运行时,遇到" ...

  7. Ubuntu下使用AMD APP编写OpenCL程序

    对于Ubuntu或其近亲(Lubuntu.Kubuntu.Mint等)编写OpenCL程序也不会太难.由于本例用的是AMD APP SDK,因此需要AMD的GPU以及相关驱动.首先,去AMD官网下载G ...

  8. 基于Ubuntu(x86)系统和STM32(Keil)编写C程序分别进行编程、验证

    文章目录 实验内容 一.基本概念 (一).全局变量 (二).局部变量 (三).堆和栈 二.编程验证 (一).基于Ubuntu用Linux系统编写C程序 (二).基于STM32用Keil编写C程序 三. ...

  9. Ubuntu 下编写C程序

    Ubuntu 下编写C程序 一.编写C程序 二.编译C程序 三.make工具和Makefile文件 一.编写C程序 使用VIM编辑器编写程序,也可以使用vscode. 1.1.设置vim编辑器 设置v ...

最新文章

  1. java 外部类似_[求指点] 如何用java 实现类似linux中管道调用外部程序的功能
  2. 6、WHERE:条件查询数据
  3. MapReduce:Simplified Data Processing on Large Clusters中文版from百度文库
  4. Fiori Elements setBusyIndicatorDelay调试的几个关键点
  5. class里面只能写以下5种
  6. java 检视_Java高并发系列——检视阅读(五)
  7. 大话数据结构第一章理解
  8. 【csdn】markdown使用教程
  9. linux video属性_Linux 下Video 的制作方法
  10. MySQL高级知识(二)——Join查询
  11. C语言 5个数最值问题
  12. Linux标准化:避免重蹈UNIX的覆辙
  13. mongodb 备份 导入导出
  14. 基本标示符-宏-编译连接
  15. HTML学生个人网站作业设计:动漫网站设计——蜡笔小新(9页) HTML+CSS+JavaScript 简单DIV布局个人介绍网页模板代码 DW学生个人网站制作成品下载
  16. 使用set集合去除重复元素
  17. 固态硬盘、机械硬盘、手机的“内存”有三种
  18. HTML实现图片点击放大效果
  19. SIPP对Freeswitch进行压力测试
  20. [日推荐]『车助手360』车主必备

热门文章

  1. Windows10系统下CUDA和cuDNN安装教程
  2. 三相同步电机怎么接线图_三相异步电动机接线图
  3. lazada发货_LAZADA怎么发货?lazada物流知识大全
  4. 齐博php百度编辑器上传图片_齐博CMS整合百度编辑器上传附件的BUG以及解决办法...
  5. 计算机维修志愿活动策划书,家电义务维修志愿者活动项目策划书.docx
  6. 2016秋季找工作纪实
  7. 实现一个英文词典的功能
  8. 网友关于DTV和IPTV的精彩论述
  9. 2014年国务院批准放假调休日期的具体安排通知
  10. 强烈给大家推荐一款简单好用免费的甘特图项目进度管理工具-进度猫