linux编译项目的命令,Linux用make指令编译进度条程序
本文實(shí)例為大家分享了Linux下寫(xiě)一個(gè)簡(jiǎn)單進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下
首先建立一個(gè)新的文件,touch progress_bar.c 執(zhí)行該vim progress_bar.c命令,寫(xiě)進(jìn)度條的程序。寫(xiě)進(jìn)一個(gè)進(jìn)度條程序:
#include
#include
#include
void progress()
{
int i = 0;
char bar[102];
memset(bar,0,102*sizeof(char));
const char* lable="|/-\\";
while(i <= 100)
{
bar[i] = '#';
printf("[%-101s] [%d%%] [%c]",bar,i,lable[i%4]);
fflush(stdout);
usleep(100000);
i++;
}
printf("\n");
}
int main()
{
progress();
return 0;
}
如圖:
該代碼中需要注意的小細(xì)節(jié):
1. const char* lable=”|/-\\”; 直接輸入一個(gè)\會(huì)被系統(tǒng)認(rèn)為是轉(zhuǎn)義,所以要輸入\\
2. printf(“[%-101s] [%d%%] [%c]”,bar,i,lable[i%4]);這里的%%同上,防止轉(zhuǎn)義。rate%4防止溢出
3. fflush(stdout); 參數(shù)為標(biāo)準(zhǔn)輸出流
4. 因?yàn)閟leep默認(rèn)單位為秒,不便于測(cè)試,usleep默認(rèn)單位為微秒
最后,進(jìn)行調(diào)試,建立一個(gè)mymakefile文件,touch mymakefile對(duì)該文件進(jìn)行編輯vim mymakefile。
myprogress_bar:progress_bar.c
g++ -o myprogress_bar progress_bar.c
:PHONY clean
clean:
rm -f myprogress_bar
如圖所示:
然后執(zhí)行make命令,對(duì)progress_bar.c文件進(jìn)行編譯,make -f mymakefile,即生成myprogress_bar文件,用./myprogress_bar對(duì)他進(jìn)行執(zhí)行。若想重新進(jìn)行編譯,則需要make -f mymakefile clean指令,先對(duì)文件progress_bar進(jìn)行清除,再用make進(jìn)行編譯。
如圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
總結(jié)
以上是生活随笔為你收集整理的linux编译项目的命令,Linux用make指令编译进度条程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux进程同步问题,关于LINUX下
- 下一篇: linux df 目录大小,Linux命