1,下载gcc
sudo apt install -y build-essential
sudo apt install gcc
gcc --version
#include<stdio.h>
#include<math.h>
int sushu(int x)
{
if(x<=1) return 0;
else
{
int k,i;
k= sqrt(x);
for(i=2;i<=k;i++)
if(x%i==0) break;
if(i<=k)
return 0;
else
return 1;
}
}
int main()
{
int x,m;
while(scanf("%d",&x)!=EOF)
{
m=sushu(x);
if(m==0)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
以下指令
gcc -E hello.c -o hello.i
gcc -S hello.i -o hello.s
gcc -c hello.s -o hello.o
gcc hello.o -o hello
作用分别是:
预处理(生成.i文件)
汇编(生成汇编代码.s文件)
编译(生成一个.obj文件)
链接(生成一个.elf文件)
3,使用gdb
若使用gcc hello.c编译,则无法直接使用gdb调试
要使用gdb调试,应用如下代码编译
gcc -g hello.c
4,使用Makefile
用vim编辑Makefile
vim Makefile