Linux Hello World!step by step

來源:互聯網
上載者:User

     雖然開發Linux程式最好還是在Linux下,但我比較懶,習慣了Windows的工作方式。就在Windows下裝了Cygwin,用UltraEdit寫程式,拿到Cygwin裡面編譯、運行。(Cygwin裡面配了一個gdb的Win視窗版,好像還不錯,有待日後研究)。要是大家知道有什麼好的IDE,不妨推薦一下哦!

1

、首先寫程式碼(C):

#include <stdio.h>
int main()
{
 printf("Hello World C!\n");
 return 0;
}

儲存成helloworld.c,我放在cygwin目錄下的home目錄下的xxx(我的使用者名稱)下,cygwin啟動時即以此為主目錄。

2、啟動cygwin

$gcc -o HelloWorld HelloWorld.c,將它編譯。

3、運行

$./ HelloWorld

顯示結果:

Hello World C!

呵呵,成功。

4、設定環境變數

   如果每次運行程式都要在檔案名稱前加上./多不爽啊。That’s all right,我們有環境變數。

   相關介紹:http://www.chinaitpower.com/2005September/2005-09-13/203823.html

   當然環境變數原本是沒有./的,只能自己加上去。

   方法一:在shell中設定

           $export PATH=$PATH:./  

   方法二:上面還是不爽,每次啟動cygwin都要設一次。其實系統內容變數就在/etc/profile檔案裡面,在第一行找個地方加上:./就行了。簡單吧!

寫完了C的helloworld,順便來個C++的:

#include <iostream>

using namespace std;

int main()

{

       std::cout<<"Hello World CPlus!"<<endl;

 return 0;

}

$ g++ -o HelloWorld HelloWorld.cpp 編譯。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.