在Linux下,用命令编译
使用 gcc -c file.c 命令会生成一个相应的 file.o。
编译完所有的.c文件之后,使用命令 gcc a.o b.o c.o -o main 会在当前目录下生成一个linux可执行文件
再使用 ./main 命令即可运行该C程序
以之前的简单链表为例
[root@iZwz94jyld0skyrwc1772eZ yeyeck]# ll total 12 -rw-r--r-- 1 root root 1795 Sep 8 21:16 list.c -rw-r--r-- 1 root root 1583 Sep 8 21:16 list.h -rw-r--r-- 1 root root 1956 Sep 8 21:16 movies.c [root@iZwz94jyld0skyrwc1772eZ yeyeck]# gcc -c list.c [root@iZwz94jyld0skyrwc1772eZ yeyeck]# ll total 16 -rw-r--r-- 1 root root 1795 Sep 8 21:16 list.c -rw-r--r-- 1 root root 1583 Sep 8 21:16 list.h -rw-r--r-- 1 root root 2712 Sep 8 21:28 list.o -rw-r--r-- 1 root root 1956 Sep 8 21:16 movies.c [root@iZwz94jyld0skyrwc1772eZ yeyeck]# gcc -c movies.c [root@iZwz94jyld0skyrwc1772eZ yeyeck]# ll total 20 -rw-r--r-- 1 root root 1795 Sep 8 21:16 list.c -rw-r--r-- 1 root root 1583 Sep 8 21:16 list.h -rw-r--r-- 1 root root 2712 Sep 8 21:28 list.o -rw-r--r-- 1 root root 1956 Sep 8 21:16 movies.c -rw-r--r-- 1 root root 4000 Sep 8 21:28 movies.o [root@iZwz94jyld0skyrwc1772eZ yeyeck]# gcc movies.o list.o -o movies [root@iZwz94jyld0skyrwc1772eZ yeyeck]# ll total 36 -rw-r--r-- 1 root root 1795 Sep 8 21:16 list.c -rw-r--r-- 1 root root 1583 Sep 8 21:16 list.h -rw-r--r-- 1 root root 2712 Sep 8 21:28 list.o -rwxr-xr-x 1 root root 13480 Sep 8 21:29 movies -rw-r--r-- 1 root root 1956 Sep 8 21:16 movies.c -rw-r--r-- 1 root root 4000 Sep 8 21:28 movies.o [root@iZwz94jyld0skyrwc1772eZ yeyeck]# ./movies Enter first movie title: yyy Enter your rating <0-10>: 5 Enter next movie title (empty line to stop): uuu Enter your rating <0-10>: 6 Enter next movie title (empty line to stop): iii Enter your rating <0-10>: 3 Enter next movie title (empty line to stop): Here is the mpvie list: Movie: yyy, Rating: 5 Movie: uuu, Rating: 6 Movie: iii, Rating: 3 You entered 3 movies. Bye! [root@iZwz94jyld0skyrwc1772eZ yeyeck]#