本文轉載自:https://www.cnblogs.com/xiaomingzaixian/p/8561790.html
1、創建C文件 test.c
指令:touch test.c
2編寫test.c文件
vim test.c
#include <stdio.h>
int main()
{
printf("welcome to here !!! \n");
return 0;
}
3、執行C文件當C程序包含其他的庫的時候比如:
#include <stdio.h>
#include <pthread.h>
int main()
{
printf("welcome to here !!! \n");
return 0;
}
此時編譯指令為:gcc -pthread test.c
有多少庫就在gcc后面加空格-XXX,還有庫就再在-XXX再空格-XXX庫
此指令回車之后會生成默認名為a.out的可執行文件,若是想生成指定名稱的可執行文件則其指令為:
gcc -o test test.c
注:此指令中-o test 表示生成的可執行文件的名稱為test