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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Ubuntu >内容正文

Ubuntu

VMware配置Ubuntu 编写c程序

發(fā)布時(shí)間:2024/3/12 Ubuntu 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VMware配置Ubuntu 编写c程序 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

    • Vmware配置Ubuntu
    • Vim的使用
    • Ubuntu配置
      • apt-get配置
        • 16.04
        • 18.04
        • 20.04
    • 編寫(xiě)程序
      • helloworld程序
      • 編寫(xiě)簡(jiǎn)單程序
        • (一)Ubuntu下的簡(jiǎn)單主/子程序
        • (二)Windows下編寫(xiě)程序
      • Ubuntu系統(tǒng)使用makefile方式編程

Vmware配置Ubuntu

參考該鏈接

Vim的使用

vim是一款編輯器,基于vi,可以通過(guò)按鍵就能完成文章的書(shū)寫(xiě),有三種使用模式。

模式作用
命令模式通過(guò)輸入vi的命令對(duì)文件的內(nèi)容進(jìn)行處理(復(fù)制、刪除、移動(dòng)等),也可以通過(guò)按光標(biāo)鍵來(lái)移動(dòng)光標(biāo)
編輯模式可以在光標(biāo)處輸入內(nèi)容
命令項(xiàng)模式命令模式下,用戶(hù)輸入冒號(hào)后,光標(biāo)會(huì)跳到底行,然后輸入命令

常用命令

命令作用
h左移光標(biāo)
l右移光標(biāo)
k上移光標(biāo)
j下移光標(biāo)
i插入內(nèi)容
l第一行插入
a光標(biāo)后插入
o當(dāng)前行插入新一行
x刪除光標(biāo)處字符
dd刪除所在行字符
X刪除光標(biāo)前的一個(gè)字符
:n1,n2 t n3把n1行到n2行的內(nèi)容復(fù)制到第n3行的下一行
:n1,n2 m n3把n1行到n2行的內(nèi)容移動(dòng)到第n3行的下一行
:w保存文件,不退出
:q不保存,退出
:wq/:x /:ZZ保存并退出

Ubuntu配置

apt-get配置

采用apt-get安裝某個(gè)軟件時(shí),默認(rèn)官方的軟件源倉(cāng)庫(kù)位于國(guó)外,下載速度慢,選擇國(guó)內(nèi)鏡像軟件源倉(cāng)庫(kù),提高安裝速度。
(1)首先切換目錄:cd /etc/apt,查看/編輯sources.list文件:sudo vi sources.list
可以看到都是國(guó)外的軟件源

(2)刪掉sources.list原本的內(nèi)容,選擇合適的源并配置,這里選擇阿里源,不同版本的Ubuntu對(duì)應(yīng)的內(nèi)容是不同的。

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)文件內(nèi)容編輯完畢,保存退出,更新源

sudo apt-get update

編寫(xiě)程序

helloworld程序

(1)打開(kāi)終端,選擇合適的位置,創(chuàng)建helloworld文件,通過(guò)vim進(jìn)行編輯文件。

(2)使用gcc命令編譯程序

gcc helloworld.c -o helloworld

gcc常用命令如下表

命令作用
gcc -E helloworld.c -o helloworld. i對(duì)helloworld.c 的程序進(jìn)行預(yù)編譯 .i做擴(kuò)展名,生成文本文件
gcc -S helloworld.i -o helloworld.s進(jìn)行編譯,生成一個(gè)匯編語(yǔ)言源程序文件.s做擴(kuò)展名,編譯后是文本文件
gcc -c helloworld.s -o helloworld.o對(duì)helloworld.s進(jìn)行匯編,生成一個(gè)可重定位目標(biāo)文件 . o作擴(kuò)展名,匯編后是二進(jìn)制文件
gcc helloworld.o -o helloworld將多個(gè)可重定位目標(biāo)文件和標(biāo)準(zhǔn)庫(kù)函數(shù),printf所在的可重定位目標(biāo)模塊printf.o進(jìn)行鏈接,生成可執(zhí)行目標(biāo)文件
gcc helloworld.c -o helloworld從c語(yǔ)言程序直接生成可執(zhí)行目標(biāo)文件
./helloworld執(zhí)行文件helloworld
(3)運(yùn)行helloworld文件
./helloworld

編寫(xiě)簡(jiǎn)單程序

(一)Ubuntu下的簡(jiǎn)單主/子程序

(1)編寫(xiě)一個(gè)main.主程序

vim main.c


編寫(xiě)子程序sub.c

(2)編譯main.c程序并運(yùn)行

(二)Windows下編寫(xiě)程序

這里使用VS2017新建一個(gè)空項(xiàng)目,編寫(xiě)main.cpp、sub.cpp、sub.h文件,點(diǎn)擊運(yùn)行,得到結(jié)果如圖。

Ubuntu系統(tǒng)使用makefile方式編程

一個(gè)工程文件中的源文件可能有很多,并且不同的功能、模塊等都放在不同的目錄中,常規(guī)的編譯已經(jīng)不能高效化的處理這樣的問(wèn)題,makefile寫(xiě)好后只需要一個(gè)make指令,即可完成makefile文件中所編寫(xiě)的所有指令,從而編譯整個(gè)工程文件。
main.c內(nèi)容

sub.h內(nèi)容

makefile內(nèi)容

hello:main.c sub2.hgcc main.c sub1.h -o hello

運(yùn)行結(jié)果

總結(jié)

以上是生活随笔為你收集整理的VMware配置Ubuntu 编写c程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。