-
教程:https://seisman.github.io/how-to-write-makefile/rules.html
-
-Wl, --as-needed
和-Wl, --no-as-needed
(LDFLAGS)https://my.oschina.net/yepanl/blog/2222870
https://www.zhihu.com/question/52043468通过指定
-Wl, --as-needed
选项,在链接的过程中,链接器会检查所有的依赖库,没有被实际用到的动态库不会被链接到可执行文件中。而-Wl, --no-as-needed
不会检查,会直接把用户指定的动态库全部写入到可执行文件中 -
CXXFLAGS
,CPPFLAGS
,CFLAGS
的关系https://stackoverflow.com/questions/495598/difference-between-cppflags-and-cxxflags-in-gnu-make:
CPPFLAGS is supposed to be for flags for the C PreProcessor; CXXFLAGS is for flags for the C++ compiler.
The default rules in make (on my machine, at any rate) pass CPPFLAGS to just about everything, CFLAGS is only passed when compiling and linking C, and CXXFLAGS is only passed when compiling and linking C++. -
$^
,$<
,$@
https://blog.youkuaiyun.com/yockie/article/details/8124817
$^
表示所有依赖的集合
$<
表示依赖目标中第一个依赖目标的名字。如果依赖目标是以模式(即"%")定义的,那么$<
将是符合模式的一系列的文件集。注意,其是一个一个取出来的。
$@
表示目标文件 -
链接选项
-I
,-l
,-L
,-Wl:rpath
https://blog.youkuaiyun.com/xianxjm/article/details/73609142
-I
编译时,查找头文件的位置
-l
链接时,需要链接的库文件
-L
链接时,库文件的位置
-Wl:rpath
运行时动态库路径,一个程序运行时,第一个寻找库文件的路径 -
=
,:=
,?=
,+=
=
使用时,make会将makefile展开后,再决定该值。所以使用的是变量最后被赋值的值。Example:x = foo y = $(x) bar x = xyz
在上例中,y的值将会是 xyz bar ,而不是 foo bar 。
:=
是覆盖之前的值,变量的值决定于它在makefile中的位置,而不是整个makefile展开后的最终值。x := foo y := $(x) bar x := xyz
在上例中,y的值将会是 foo bar ,而不是 xyz bar 了。
?=
是如果没有被赋值过就赋予等号后面的值
+=
是添加等号后面的值