# introduction for rules # $@ 表示目标文件 # $^ 表示所有的依赖文件 # $< 表示第一个依赖文件 # $? 表示比目标还新的依赖文件列表 # example # main: main.o hello.o hi.o # gcc -o main main.o hello.o hi.o # 其中,main就是目标文件,所有的依赖文件为 main.o hello.o hi.o # 此时,...
#*tousenon-standardC/C++libraries,setpre-processororcompiler #optionstoandlinkeronesto #(SeeMakefile.gtk+-2.0foranexample)#*tosearchsourcesinmoredirectories,setto<SRC_DIRS> #*tospecifyyourfavoriteprogramname,setto<APP> #3.Typemaketostartbuildingyourprogram.# #MakeTarget:#--- #TheMakefileprovides...
拿C语言来说,编译的时候 gcc 只会默认链接一些基本的C语言标准库,很多源文件依赖的标准库都需要我们手动链接。 下面列举了一些需要我们手动链接的标准库: name1.c 用到了数学计算库 math 中的函数,我们得手动添加参数 -Im; name4.c 用到了小型数据库 SQLite 中的函数,我们得手动添加参数 -lsqlite3; name5....
这个Makefile 支持 C、C++ 以及 C/C++ 混合三种编译方式: 如果只指定 .c 扩展名,那么这是一个 C 程序,用 $(CC) 表示的编译命令进行编译和连接。 如果指定的是除 .c 之外的其它扩展名(如 .cc、.cpp、.cxx 等),那么这是一个 C++ 程序,用 $(CXX) 进行编译和连接。 如果既指定了 .c,又指定了其它 ...
Makefile 静态模式 %.o:%.c 静态模式可以更加容易地定义多目标的规则,可以让我们的规则变得更加的有弹性和灵活。 语法: <targets ...>: <target-pattern>: <prereq-patterns ...> <commands> ... 如果我们的定义成“%.o”,意思是我们的集合中都是以“.o”结尾的,而如果我们的定义成“%.c”, 意思是...
让我们创建一个更典型的 Makefile - 一个编译单个 C 文件的文件。但在我们这样做之前,请创建一个名为的文件,该文件blah.c具有以下内容: // blah.c int main() { return 0; } 然后创建 Makefile(Makefile一如既往地称为): blah: cc blah.c -o blah ...
# Generic Makefile for C/C++ Program # # License: GPL (General Public License) # Author: whyglinux <whyglinux AT gmail DOT com> # Date: 2006/03/04 (version 0.1) # 2007/03/24 (version 0.2) # 2007/04/09 (version 0.3) # 2007/06/26 (version 0.4) ...
# This makefile just is a example.test.o:test.c test.h gcc-c test.cclean:rm-f*.o 运行make clean时,执行rm –f *.o命令,删除编译过程中生成的所有的以 .o 结尾的文件。 2、Makefile的基本内容 Makefile一般包括包含:显式规则、变量定义、隐含规则、文件指示和注释等五个内容。
gcc -c $< 这个规则表示所有的.o文件都是依赖于相应的.c文件的 6. Example for Makefile --- #It is a example for describingmakefile prog : filea.o fileb.o filec.o cc filea.o fileb.o filec.o -LS -o prog filea.o : filea.c a.h defs ...
foo=one two threeall:foriin$(foo);do\ echo $$i;\ end 就可以正常打印:one two three。 这是因为$i命令被make翻译成了shell中的i,而此时shell中的i的值就是one two three. 通配符 在Makefile中,*和%是都属于通配符。下面来看下他们的用法。