手动
gcc
编译多个文件
和利用
makefile
编译多个文件的区别
[root@localhost ~]# cd /export
[root@localhost export]# ls
a.out hello hello.c hello.o main.tgz thanks.c
[root@localhost export]# tar -zxfv main.tgz
tar (child): v: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@localhost export]# ls
a.out hello hello.c hello.o main.tgz thanks.c
[root@localhost export]# tar -zxvf main.tgz
cos_value.c
haha.c
main.c
sin_value.c
[root@localhost export]# ls
a.out haha.c hello.c main.c sin_value.c
cos_value.c hello hello.o main.tgz thanks.c
[root@localhost export]# cat main.c
#include <stdio.h>
#define pi 3.14159
char name[15];
float angle;
int main(void)
{
printf ("\n\nPlease input your name: ");
scanf ("%s", &name );
printf ("\nPlease enter the degree angle (ex> 90): " );
scanf ("%f", &angle );
haha( name );
sin_value( angle );
cos_value( angle );
}
[root@localhost export]# cat haha.c
#include <stdio.h>
int haha(char name[15])
{
printf ("\n\nHi, Dear %s, nice to meet you.", name);
}
[root@localhost export]# ls
a.out haha.c hello.c main.c sin_value.c
cos_value.c hello hello.o main.tgz thanks.c
[root@localhost export]# cat sin_value.c
#include <stdio.h>
#include <math.h>
#define pi 3.14159
float angle;
void sin_value(void)
{
float value;
value = sin ( angle / 180. * pi );
printf ("\nThe Sin is: %5.2f\n",value);
}
[root@localhost export]# cat cos_value.c
#include <stdio.h>
#include <math.h>
#define pi 3.14159
float angle;
void cos_value(void)
{
float value;
value = cos ( angle / 180. * pi );
printf ("The Cos is: %5.2f\n",value);
}
手动编译成目标文件
[root@localhost export]# gcc -c main.c
[root@localhost export]# ls