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

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

问题描述

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

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/

天真地,/lib/../lib/ 似乎与 /lib/ 是同一目录 —lib 的父母将有一个名为 lib 的孩子,那个人的父亲的儿子是我父亲的儿子的儿子"等等./usr/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. 是否有某种原因,可能与符号链接有关,g++ 应该配置为同时搜索​​ /lib/../lib//lib/?

如果这是不必要的冗余,人们将如何解决它?

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

如果重要的话,这是在未修改的 Ubuntu 9.04 安装上观察到的.

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

更多信息.

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

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

LIBRARY_PATH 和 LPATH 都不是从 printenv 输出的,并且 echo $LPATHecho LIBRARY_PATH 都返回空行.

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

推荐答案

一个答案的尝试(我从查看 gcc.c 驱动程序源和 Makefile 环境的几分钟中收集到).

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 前缀(参见 GCC 文档 关于 GCC_EXEC_PREFIX)
  2. $LIBRARY_PATH 环境变量
  3. $LPATH 环境变量(被视为 $LIBRARY_PATH)
  4. 传递给 -B 命令行开关的任何值
  5. 标准可执行前缀(在编译时指定)
  6. 工具目录前缀
  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

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

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)/../" 

但是,这些是针对特定于编译器版本的路径.您的示例可能受到我上面列出的环境变量的影响(LIBRARY_PATHLPATH)

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天全站免登陆