歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux應用程序Helloworld入門

Linux應用程序Helloworld入門

日期:2017/3/1 10:38:03   编辑:Linux編程

對於初學者來說(本人就是),如何開始寫第一個程序至關重要。有的時候一個簡單的問題會嚴重影響到學習的積極性和自信心。

這裡結合實際工作中的一些經驗,總結方法步驟,對Linux下應用程序Helloworld入門做一個簡單的介紹。不僅僅作為一個個人的小結,也希望能對各位學習中的朋友能有幫助。

第一步:首先需要一個Ubuntu系統,可以是PC機,服務器,甚至是虛擬機(比如Vmware);

第二步:在ubuntu系統上安裝gcc編譯器,可以采用如下命令;

$ sudo apt-get install gcc

gcc 版本如下:


第三步:使用vim或者vi編輯器,編輯app_helloworld.c文件;

$ vi app_helloworld.c

app_helloworld.c文件內容如下:

  1. #include <stdio.h>
  2. int main(int argc, char **argv)
  3. {
  4. printf("Hello world, this is my first app!\r\n");
  5. return 0;
  6. }

第四步:編譯app_helloworld.c

$ gcc -o app_helloworld app_helloworld.c

第五步:運行app_helloworld程序



到這裡,相信Linux下簡單的Helloworld應用程序應該已經非常明白了。這裡僅僅是做一個衍生的思考,Helloworld是如何運行起來的?我們看看這個應用程序依賴了什麼?


分析下我們可以看到printf是由libc.so.6提供的函數實現,而另外兩個又是什麼呢?大家可以發散下思維。

Copyright © Linux教程網 All Rights Reserved