Under Linux, use the command to compile
Using the gcc -c file.c command will generate a corresponding file.o.
After compiling all the .c files, use the command gcc ao bo co -o main to generate a linux executable file in the current directory
Then use the ./main command to run the C program
Take the previous simple linked list as an example
[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]#
Similar Posts:
- [Solved] MYSQL ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mys…
- Grub cannot be started after Linux is installed
- sudo: /etc/sudoers is world writable sudo: no valid sudoers sources found, q…
- Ubuntu Error: No module named ‘apt_pkg’ (Step-by-Step Tutorial)
- [Solved] Pandas Parses MovieLens 1M Dataset Error: UnicodeDecodeError
- [Solved] Linux: ‘readonly’ option is set add-command line save error
- DDMS [Android device monitor] cannot be opened after Android studio 3.0
- Solution of 80 port occupied by system (PID = 4) in win10
- MySQLAccess denied for user ‘root’@’localhost’ [How to Solve]
- How to Solve Datatable field value is empty Error