GNU make manual 翻译( 九十六)

简介:
继续翻译

复制代码
4.5.6 Directory Search for Link Libraries                        
-----------------------------------------                        
                        
Directory search applies in a special way to libraries used with the linker.  This special feature comes into play when you write a prerequisite whose name is of the form `-lNAME'.  (You can tell something strange is going on here because the prerequisite is normally the name of a file, and the _file name_ of a library generally looks like `libNAME.a', not like `-lNAME'.)                        
                        
   When a prerequisite's name has the form `-lNAME', `make' handles it
specially by searching for the file `libNAME.so', and, if it is not
found, for the file `libNAME.a' in the current directory, in directories specified by matching `vpath' search paths and the `VPATH' search path, and then in the directories `/lib', `/usr/lib', and `PREFIX/lib' (normally `/usr/local/lib', but MS-DOS/MS-Windows versions  of `make' behave as if PREFIX is defined to be the root of the DJGPP installation tree).                        
                        
   For example, if there is a `/usr/lib/libcurses.a' library on your system (and no `/usr/lib/libcurses.so' file), then 
     foo : foo.c -lcurses                        
             cc $^ -o $@ 
would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be executed when `foo' is older than `foo.c' or than                        
`/usr/lib/libcurses.a'.                        
复制代码
4.5.6 对链接库的目录搜索
-----------------------------------------

对被链接器所使用的库,目录搜索采用特殊的方式。当你以-lNMAE格式来写前提条件时,这种特殊的功能将其作用。(你可以说有些奇怪的事情正在进行,因为正常的前提条件是一个文件的民自,并且一个库的文件名通常是 libNMAE.a 之类,而不是 像 -lNMAE 的样子)

 

当一个前提条件的名字中有 -lNAME 的格式,make 要对其进行特殊处理,搜索 libNAME.so ,如果没有找到,则搜索 libNAME.a。此种搜索是在 当前目录和vpath 搜索路径和 VPATH 搜索路径中进行,再然后是 /lib, /usr/lib ,PREFIX/lib (通常是 /usr/local/lib ,但是 MS-DOS/MS-Windows 版本的make 会把PREFIX 处理成 DJGPP 安装目录的根目录)

例如,如果有你的系统里有一个 /usr/lib/libcurses.a 库(并且没有 /usr/lib/libcurses.so 文件)则

foo : foo.c -lcurses
cc $^ -o $@

将会导致,如果foo比 foo.c 或者 /usr/lib/libcurses.a 旧,则执行 cc foo.c /usr/lib/libcurses.a -o foo

后文待续


本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/09/20/2694641.html,如需转载请自行联系原作者
目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到
|
C语言 C++ Perl
如何处理错误消息Please install the gcc make perl packages
如何处理错误消息Please install the gcc make perl packages
142 0
|
3月前
|
NoSQL 编译器 开发工具
006.gcc编译器
gcc是什么?
44 0
006.gcc编译器