【gcc 编译 】
如 demo 目录下 有一个 abc.c 需要编译,则:gcc ./abc.c -o abc
执行: ./abc
说明: ./ 表示当前目录下
【关于 make】
(1) 一个C程序需要 编译,链接。在编译的时候,将产生 .o 目标文件,链接时将产生 可执行文件。
(2) 如果一个程序有多个源文件要编译,链接,手工去逐个去做将会麻烦很大。make命令就帮我们完成这项工作。
(3)make 命令的执行时依赖于一个 makefile文件(文件名就是 Makefile或者 makefile,无后缀名)。
(4)如何写makefile文件? 举例如下:有三个文件,一个叫 abc.c ,含有 main的主文件;一个叫add.c文件,它有一个add方法;另外一个叫 add.h头文件,对add.c进行声明的一个文件。
abc.c:
#include "stdio.h"
#include "add.h"
int main()
{
printf("hello unix c !\n");
printf("sum is :%d\n" , add(2,3));
return 0;
}
add.c:
int add(int a,int b)
{
return a + b;
}
add.h
extern int add(int a, int b);
现在要对三个文件进行编译,链接,一步完成,这时,就要书写 makefile 文件了
test:abc.o add.o
#pay attention : the tab before gcc Command ,hehehehe
gcc abc.o add.o -o test
abc.o:abc.c add.h
gcc -c abc.c -o abc.o
add.o:add.c add.h
gcc -c add.c -o add.o
对makefile文件内容,做个简单解释如下:
第一行: 程序 test 将使用两个 目标文件 abc.o 和 add.o,注意第二行的tab分隔符,一定要!!
第二行:将两个目标文件 链接生产为 test可执行文件
第三、四行:解释了 abc.o如何产生
第五、六行:解释了add.o如何产生
(5)执行make :在当前目录下输入“ make” ,ok ,产生 test 可执行文件, 在当前目录下执行 使用 “ ./test”
分享到:
相关推荐
You've experienced the shiny, point-and-click surface of your Linux computer-now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very ...
All Linux users and administrators tend to like the flexibility and speed of Linux administration from the command line in byte–sized chunks, instead of fairly standard graphical user interfaces....
本书是The Linux Command Line 的中文版,帮助新手入门和老鸟进阶,可以中英文对照着读,效果更佳(小小搬运工,省的大家去找,不喜勿喷)
The Linux Command Line; 2019/1/28; 19.01; This book is part of the LinuxCommand.org project
This book is part of the LinuxCommand.org project, a site for Linux education and advocacy devoted to helping users of legacy operating systems migrate into the future. You may contact the Linux...
linux command (全) 介绍各种linux指令代码,相当的全。
linux command line.pdf 介绍关于linux命令行的知识。
The Linux command line.pdf 英文版 此书英文本是免费的
The Linux Command Line电子书中英文版本合集。学习 Linux 命令行会让你受益匪浅,给你极大的回报。如果你认为, 现在你已经是高手了。别急,其实你还不知道什么才是真正的高手。不像其他一些计算机技能, 一段时间...
The Linux Command Line 中文版 高清
Designed for the new command line user, this 555-page volume covers the same material as LinuxCommand.org but in much greater detail. In addition to the basics of command line use and shell scripting,...
The Linux Command Line: A Complete Introduction
The Linux Command Line英文版
The Linux command line tool(快乐的linux命令行)中文高清版,无水印
Apress - Beginning The Linux Command Line, 2009.zip
Linux Command Background Linux Command Background Linux Command Background
The Linux Command Line, 2nd Edition: A Complete Introduction (True PDF)
The Linux Command Line A Complete Introduction可遇不可求的linux教学资源
command line to tell a Linux system what to do. Here’s an example command that counts lines of text in a file, myfle: wc -l myfile We’ll cover the most important Linux commands for the aver‐ age ...
英文版本的The linux command line下载积分最少的。多谢