[root@study ~]#
gcc
-
o hello hello.o
[root@study ~]#
ll hello*
-
rwxr
-
xr
-
x
. 1 root root 8503 Sep 4 11:35
hello
<==
这
就是可
执
行文件!
-
o
的
½
果
-
rw
-
r
--
r
--
. 1 root root 71 Sep 4 11:32 hello.c
-
rw
-
r
--
r
--
. 1 root root 1496 Sep 4 11:34 hello.o
[root@study ~]#
./hello
Hello World
这个步骤主要是利用
hello.o
这个目标文件制作出一个名为
hello
的执行文件,详细的
gcc
语法我
们会在后续章½中继续½绍!透过这个动作后,我们可以得到
hello
及
hello.o
两个文件,
真正可
以执行的是
hello
这个
binary program
喔!
或许你会觉得,咦!只要一个动作作出
a.out
就好了,
干嘛还要先制作目标文件再做成执行档呢?
呵呵!透过下个范例,你就可以知道为什么啦!
21.2.2
主、子程序链½:子程序的编译
如果我们在一个主程序里面又呼½了另一个子程序呢?这是很常见的一个程序写法,
因为可以简化
整个程序的易读性!在底下的例子当中,我们以
thanks.c
这个主程序去呼½
thanks_2.c
这个子程序,
写法很简单:
.
撰写所需要的主、子程序
# 1.
编辑
主程序:
[root@study ~]#
vim thanks.c
#include <stdio.h>
int
main(void)
{
printf("Hello World
\
n");
thanks_2();
}
#
上面的
thanks_2();
那一行就是呼½子程序啦!
[root@study ~]#
vim thanks_2.c
#include <stdio.h>
void thanks_2(void)
{
printf("Thank you!
\
n");
}
上面这两个文件你可以到底下下载:
.
http://linux.vbird.org/linux_basic/0520source/thanks.c
.
http://linux.vbird.org/linux_basic/0520source/thanks_2.c