使用gcc編譯c程式
完整的執行過程如圖所示:
1 cd ~ //切換到home下面,ubuntu中~就是home
2 ls //展開home目錄下面的檔案
3 mkdir aaaa //新建乙個目錄aaaa,即新建乙個資料夾
4 cd aaaa //切換到aaaa下面
5 vim first.c //使用vim新建乙個名為first.c的檔案,
/* 之後在vim下面按 i 鍵入insert模式,
然後輸出如下程式
#include
void main(void)
編輯完成之後再按esc鍵進入命令模式
再輸出:w 儲存該檔案,
最後輸入q:退出vim
*/6 gcc first.c -o first //把first.c 編譯成first可執行檔案
7 ls //列出aaaa目錄下面所有的檔案
//多出來乙個綠色的first檔案
8 ./first //在當前路徑上面執行first檔案
//可以看到執行程式之後輸出來 "hello world!"
9 ls -l
可以看到first檔案具有x屬性,即first是可執行檔案
在windows下面是看字尾分別乙個檔案是否可以被執行,但是linux下面
只要乙個檔案具有x屬性,那它就能被執行。所以執行first會有輸出。
gcc編譯C 程式
單個原始檔生成可執行程式 下面是乙個儲存在檔案 helloworld.cpp 中乙個簡單的 c 程式的 helloworld.cpp include int main int argc,char argv 程式使用定義在標頭檔案 iostream 中的 cout,向標準輸出寫入乙個簡單的字串。該 可...
gcc編譯C 程式
單個原始檔生成可執行程式 下面是乙個儲存在檔案 helloworld.cpp 中乙個簡單的 c 程式的 helloworld.cpp include int main int argc,char argv 程式使用定義在標頭檔案 iostream 中的 cout,向標準輸出寫入乙個簡單的字串。該 可...
gcc編譯C 程式
單個原始檔生成可執行程式 下面是乙個儲存在檔案 helloworld.cpp 中乙個簡單的 c 程式的 helloworld.cpp include int main int argc,char ar std cout hello,world std endl return 0 程式使用定義在標頭檔...