g ++搜索/lib/../lib/,然后/ lib / [英] g++ searches /lib/../lib/, then /lib/

查看:135
本文介绍了g ++搜索/lib/../lib/,然后/ lib /的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 g ++ -print-search-dirs ,我的C ++编译器正在许多目录中搜索库,包括...




  • / lib /../ lib /:

  • / usr / lib /../ lib /:

  • / lib /:

  • / usr / lib /



code> / lib /../ lib / 看起来与 / lib / — lib的父母将有一个名为lib的孩子,那人的父亲的儿子是我父亲的儿子的儿子等等。这同样适用于 / usr / lib /../ lib / / usr / lib /


  1. 是否有一些原因,可能与符号链接有关,g ++应该配置为同时搜索​​ / lib /../ lib / / lib /


  2. 如果这是不必要的冗余,那么如何解决它?


重要的是,这是在未修改的Ubuntu 9.04安装中观察到的。

编辑:更多信息



结果来自执行 g ++ -print-search-dirs 没有其他开关,来自bash shell。

LIBRARY_PATH和LPATH都不是从 printenv 输出的,而是 echo $ LPATH echo LIBRARY_PATH return blank lines。

解决方案

尝试一个答案(我从几分钟的时间内收集了 gcc.c 驱动程序源代码和Makefile环境)。



这些路径是在运行时从以下位置构建的:


  1. GCC exec前缀(参见 GCC_EXEC_PREFIX 的gnsite.ualberta.ca/Documentation/Gnu/gcc-3.0.2/html_node/gcc_53.htmlrel =nofollow noreferrer> GCC文档。 ) $ LIBRARY_PATH 环境变量

  2. $ LPATH 环境变量(对待 $ LIBRARY_PATH

  3. 任何传递给 -B 命令行开关

  4. 标准可执行文件前缀(如编译期间指定的那样)

  5. ldir prefix

最后一个(tooldir前缀)通常被定义为相对路径:
从gcc的 Makefile.in

 #编译器查找库等的目录
libsubdir = $(libdir)/ gcc / $(target_noncanonical)/ $(version)
#编译器找到可执行文件的目录
libexecsubdir = $(libexecdir)/ gcc / $(target_noncanonical)/ $ (版本)
#用于在gcc.o中生成一个相对$(gcc_tooldir)
unlibsubdir = ../../ ..
....
#作为编译标志,因此它们将tooldir基础前缀
#定义为../../../../,并将库搜索前缀中的一个定义为../../../
#这些获得PREFIX追加,然后机器为其构建的gcc
#ie ie484-linux-gnu,得到如下所示:
#/ usr / lib / gcc / i486-linux-gnu /4.2.3/../../../../i486-linux-gnu/lib/../lib/
DRIVER_DEFINES = \
-DSTANDARD_STARTFILE_PREFIX = \$( unlibsubdir)/ \\
-DTO OLDIR_BASE_PREFIX = \$(unlibsubdir)/../ \\

然而,这些是针对编译器版本特定的路径。你的例子很可能受上面列出的环境变量( LIBRARY_PATH LPATH )影响


According to g++ -print-search-dirs my C++ compiler is searching for libraries in many directories, including ...

  • /lib/../lib/:
  • /usr/lib/../lib/:
  • /lib/:
  • /usr/lib/

Naively, /lib/../lib/ would appear to be the same directory as /lib/ — lib's parent will have a child named lib, "that man's father's son is my father's son's son" and all that. The same holds for /usr/lib/../lib/ and /usr/lib/

  1. Is there some reason, perhaps having to do with symbolic links, that g++ ought to be configured to search both /lib/../lib/ and /lib/?

  2. If this is unnecessary redundancy, how would one go about fixing it?

If it matters, this was observed on an unmodified install of Ubuntu 9.04.

Edit: More information.

The results are from executing g++ -print-search-dirs with no other switches, from a bash shell.

Neither LIBRARY_PATH nor LPATH are output from printenv, and both echo $LPATH and echo LIBRARY_PATH return blank lines.

解决方案

An attempt at an answer (which I gathered from a few minutes of looking at the gcc.c driver source and the Makefile environment).

These paths are constructed in runtime from:

  1. GCC exec prefix (see GCC documentation on GCC_EXEC_PREFIX)
  2. The $LIBRARY_PATH environment variable
  3. The $LPATH environment variable (which is treated like $LIBRARY_PATH)
  4. Any values passed to -B command-line switch
  5. Standard executable prefixes (as specified during compilation time)
  6. Tooldir prefix

The last one (tooldir prefix) is usually defined to be a relative path: From gcc's Makefile.in

# Directory in which the compiler finds libraries etc.
libsubdir = $(libdir)/gcc/$(target_noncanonical)/$(version)
# Directory in which the compiler finds executables
libexecsubdir = $(libexecdir)/gcc/$(target_noncanonical)/$(version)
# Used to produce a relative $(gcc_tooldir) in gcc.o
unlibsubdir = ../../..
....
# These go as compilation flags, so they define the tooldir base prefix
# as ../../../../, and the one of the library search prefixes as ../../../
# These get PREFIX appended, and then machine for which gcc is built
# i.e i484-linux-gnu, to get something like: 
# /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../i486-linux-gnu/lib/../lib/
DRIVER_DEFINES = \
-DSTANDARD_STARTFILE_PREFIX=\"$(unlibsubdir)/\" \
-DTOOLDIR_BASE_PREFIX=\"$(unlibsubdir)/../\" \

However, these are for compiler-version specific paths. Your examples are likely affected by the environment variables that I've listed above (LIBRARY_PATH, LPATH)

这篇关于g ++搜索/lib/../lib/,然后/ lib /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆