日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

VMware配置Ubuntu 编写c程序

發布時間:2024/3/12 Ubuntu 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。