使用gcc
运行-Wl,--verbose
会打印
attempt to open /foo/gcc-6.3.0/lib64/../lib64/libm.so failed
attempt to open /foo/gcc-6.3.0/lib64/../lib64/libm.a failed
attempt to open /foo/gcc-6.3.0/lib/x86_64-redhat-linux/6.3.0/libm.so failed
attempt to open /foo/gcc-6.3.0/lib/x86_64-redhat-linux/6.3.0/libm.a failed
attempt to open /foo/gcc-6.3.0/lib/../lib64/libm.so failed
attempt to open /foo/gcc-6.3.0/lib/../lib64/libm.a failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/libm.so failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/libm.a failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/../../../x86_64-redhat-linux/6.3.0/libm.so failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/../../../x86_64-redhat-linux/6.3.0/libm.a failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/../../../../lib64/libm.so failed
attempt to open /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/../../../../lib64/libm.a failed
attempt to open /lib/../lib64/libm.so failed
attempt to open /lib/../lib64/libm.a failed
attempt to open /usr/lib/../lib64/libm.so succeeded
这些路径是否需要在其中包含一堆../
?例如,为什么/foo/gcc-6.3.0/lib64/../lib64/libm.so
不仅仅是/foo/gcc-6.3.0/lib64/libm.so
?此外,一些较长的路径扩展到相同的东西,例如, /foo/gcc-6.3.0/lib/gcc/x86_64-redhat-linux/6.3.0/../../../../lib64/libm.so
和/foo/gcc-6.3.0/lib/../lib64/libm.so
。
此外,明显缺少/foo/gcc-6.3.0/lib
,而大多数库都安装在lib
而不是lib64
。
答案 0 :(得分:0)
我在这里发现了两个类似的问题:
Why does g++ look in LIBRARY_PATH/../lib64 and where is this documented?
g++ searches /lib/../lib/, then /lib/
评论here阐明了决定这些路径形成的方式。
然而,这些并没有回答为什么使用这么多路径,即使它们解析到同一目录。
答案 1 :(得分:0)
/foo/gcc-*
中的库由gcc-*
个包提供,这是/lib64/
或/lib
中提供的实际库的符号链接。
这些符号链接为gcc
提供了有针对性的支持。
实际的库包含共享库。
以gcc-objc
为例,以及它所指向的库libobjc
。
$ rpm -ql gcc-objc
<snip>
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/include/objc/thr.h
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/include/objc/typedstream.h
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libobjc.a
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libobjc.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.7
<snip>
$ ls -l /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libobjc.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libobjc.so -> ../../../../lib64/libobjc.so.2
$ rpm -ql libobjc
/usr/lib64/libobjc.so.2
/usr/lib64/libobjc.so.2.0.0
现在让我们看看这些软件包的描述。
$ rpm -qi gcc-objc
gcc-objc provides Objective-C support for the GCC.
Mainly used on systems running NeXTSTEP, Objective-C is an
object-oriented derivative of the C language.
$ rpm -qi libobjc
This package contains Objective-C shared library which is needed to run
Objective-C dynamically linked programs.