【C语言】linux 下多文件编译

简介: 在Linux下,用命令编译 使用 gcc -c file.c 命令会生成一个相应的 file.o。 编译完所有的.c文件之后,使用命令 gcc a.o b.o c.o -o main 会在当前目录下生成一个linux可执行文件 再使用 .

在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]# 

 

相关文章
|
4天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
22 0
|
23天前
|
人工智能 安全 Linux
【Linux】Linux之间如何互传文件(详细讲解)
【Linux】Linux之间如何互传文件(详细讲解)
|
1天前
|
人工智能 Linux
Linux查找大文件的方法
Linux查找大文件的方法
|
3天前
|
固态存储 Ubuntu Linux
Linux(29) 多线程快速解压缩|删除|监视大型文件
Linux(29) 多线程快速解压缩|删除|监视大型文件
11 1
|
3天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(24) 如何在Ubuntu中操作rootfs.img文件
Linux(24) 如何在Ubuntu中操作rootfs.img文件
9 0
|
3天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
6 0
|
8天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
17 0
|
9天前
|
Linux Shell 开发工具
Linux文件常用操作
Linux文件常用操作(几乎覆盖所有日常使用)
84 0
|
11天前
|
Linux 内存技术 Perl
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
|
16天前
|
Linux
linux 超过4个G的文件传不上去的解决办法
linux 超过4个G的文件传不上去的解决办法
9 0