當前位置:編程學習大全網 - 編程軟體 - 如何使用makefile?

如何使用makefile?

以hello_test.c文件為例

1.創建程序

在linux控制臺界面下 ,輸入vi hello_test.c,輸入i進入編輯插入模式,輸入代碼如下:

#include <stdio.h>

int main(void)

{

printf("Hello,Word!/n");

return 0;

}

用gcc編譯程序

輸入命令:gcc hello_test.c

輸入命令:ls

顯示:a.out hello_test.c

輸入命令:./a.out //執行程序

2.使用Makefile

(1)創建Makefile,在hello_test.c所在目錄輸入 vi Makefile

(2)輸入Makefile內容。在vi插入模式下輸入:

hello_test : hello_test.c

gcc -o hello_test hello_test.c //特別註意 gcc前面不是空格,而是tab間隔符,否則會出現makefile:2: *** 遺漏分隔符錯誤

clean :

rm -fr hello_test *.o *.core

(3)輸入make,屏幕輸出 gcc -o hello_test hello_test.c,表示編譯已經通過。

生成 hello_test。

  • 上一篇:抖音心心相依多少抖幣
  • 下一篇:編程規範入門篇 空格和tab的區別和技巧
  • copyright 2024編程學習大全網