Instead of giving -Wl,-rpath=$HOME/local/gcc52/lib64
to each invocation of GCC 5.2 which I built from the source, I modified its spec
file in this way:
我没有给每个从源代码构建的GCC 5.2调用-Wl,-rpath = $ HOME / local / gcc52 / lib64,而是以这种方式修改了它的spec文件:
*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S: %(linker) -rpath=%:getenv(HOME /local/gcc52/lib64) ...
But this depends on my specific installation under $HOME/local/gcc52
. Are there better way to refer to the installation path of the invoked GCC itself?
但这取决于我在$ HOME / local / gcc52下的具体安装。有没有更好的方法来引用调用的GCC本身的安装路径?
This manual page did not help me much:
本手册页对我帮助不大:
- https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
- https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
2 个解决方案
#1
2
As far as I can tell, GCC is very much dependent on the installation folder it was compiled for. I build RTEMS cross-compilation toolchains very frequently, and one of the first things I learned was that there are many places in the generated cross-compiler where the installation prefix (i.e. whatever was passed to --exec-prefix
) is "burned" in.
据我所知,GCC非常依赖于它编译的安装文件夹。我经常构建RTEMS交叉编译工具链,我学到的第一件事就是生成的交叉编译器中有很多地方安装前缀(即传递给--exec-prefix的任何内容)被“烧掉”在。
"Learned" - as in, I tried to move the compiler's folder to a different path, and all hell broke loose :-)
“学到了” - 就像在,我试图将编译器的文件夹移动到另一条路径,并且所有地狱都松了一口气:-)
My point: modifying specs
files to make them point to paths in your install seems absolutely normal, as far as GCC is concerned.
我的观点:就GCC而言,修改specs文件以使它们指向安装中的路径似乎绝对正常。
#2
0
When you’re compiling GCC, you need to pass the prefix you want to configure
anyway. At that time, you can also give it the --with-specs
option. Based on my experiments, the option --with-specs='%{!static:%x{-rpath='$prefix'/lib64} %x{-enable-new-dtags}}'
(where $prefix should be replaced by the same path you pass to
--prefix`) works (you need something more complicated for multilib support, of course).
在编译GCC时,无论如何都需要传递要配置的前缀。那时,你也可以给它--with-specs选项。根据我的实验,选项--with-specs ='%{!static:%x {-rpath ='$ prefix'/ lib64}%x {-enable-new-dtags}}'(其中$ prefix应该是替换为您传递给的相同路径 - 前缀`)工作(当然,您需要一些更复杂的multilib支持)。
Things to note:
注意事项:
- This isn’t properly documented anywhere, but it appears that, unlike with regular spec files, the
--with-specs
configure option applies to the command-line arguments passed to GCC itself. Thus, you can’t just try to modify the*link
spec string. - 这在任何地方都没有正确记录,但似乎与常规规范文件不同,--with-specs configure选项适用于传递给GCC本身的命令行参数。因此,您不能只是尝试修改* link规范字符串。
- The
%x
sequence doesn’t change the GCC command line, but accumulates arguments to pass to the linker. That’s why I pass-rpath
and-enable-new-dtags
directly instead of via-Wl
. - %x序列不会更改GCC命令行,但会累积参数以传递给链接器。这就是为什么我直接通过-rpath和-enable-new-dtags而不是通过-Wl。
- There are a bunch of suggestions online for what specs to pass. I didn’t see this one anywhere, so it take it with a grain of salt. The reason I used my own is that all the others either modify a spec string like
*link
, which you cannot do with--with-specs
, or they add options to the GCC command line using-Wl
, which I’m fairly sure somebody said they had trouble with because in some cases it confused GCC when they weren’t linking. YMMV. - 网上有很多建议可以通过哪些规范。我没有在任何地方看到这个,所以它带着一粒盐。我使用自己的原因是所有其他人都修改了像* link这样的规范字符串,你无法使用--with-specs,或者他们使用-Wl向GCC命令行添加选项,我很确定有人说他们有麻烦,因为在某些情况下,当他们没有链接时,它会混淆GCC。因人而异。
- If you use bootstrapping (which you usually are unless building a cross-compiler, in which case I could be wrong but I don’t think this particular rpath trick is useful anyway), this will add a
RUNPATH
to the GCC programs and shared libraries as well. This seems to be the correct option, because they were compiled against the libraries that are now in$prefix/lib64
, but it’s worth noting. - 如果你使用bootstrapping(除非你构建一个交叉编译器,你通常会这样做,在这种情况下我可能会错,但我不认为这个特殊的rpath技巧是有用的),这将为GCC程序和共享库添加一个RUNPATH同样。这似乎是正确的选项,因为它们是针对现在在$ prefix / lib64中的库编译的,但值得注意。
-
I added
-enable-new-dtags
, which puts this inDT_RUNPATH
instead ofDT_RPATH
. This is the newer attribute which all the documentation says should be preferred, <sarcasm>which is why it requires an extra flag which isn’t clearly cross-referenced in the docs</sarcasm>. Among the differences between RPATH and RUNPATH are:我添加了-enable-new-dtags,它将它放在DT_RUNPATH而不是DT_RPATH中。这是所有文档中应该首选的新属性,
这就是为什么它需要一个额外的标志,而这个标志在docs 中没有明确的交叉引用。 RPATH和RUNPATH之间的区别在于: - If RUNPATH is present, RPATH will be completely ignored.
- 如果存在RUNPATH,则将完全忽略RPATH。
- The RPATH overrides
LD_LIBRARY_PATH
; the RUNPATH does not. - RPATH覆盖LD_LIBRARY_PATH; RUNPATH没有。
- They work somewhat differently for dependencies of dependencies (
RUNPATH
is only searched for direct dependencies;RPATH
is searched for indirect dependencies as long as nothing in the dependency chain has aRUNPATH
). More details are available here. - 它们对依赖项的依赖性的工作方式有所不同(RUNPATH仅搜索直接依赖项;只要依赖项链中没有任何内容具有RUNPATH,就会搜索RPATH的间接依赖项)。更多细节可在此处获得。
- I think that’s everything, but I wouldn’t be surprised if I’m missing something.
- 我认为这就是一切,但如果我遗失了什么,我不会感到惊讶。
As the article I linked above indicates, not everybody prefers RUNPATH to RPATH, but here it shouldn’t be an issue unless you mix code from different compilers requiring different compiler support libraries in a complicated way, and if you do that I don’t think there’s any one-size-fits-all solution.
正如我在上面链接的文章所指出的那样,并不是每个人都喜欢RUNPATH到RPATH,但这里不应该是一个问题,除非你以复杂的方式混合需要不同编译器支持库的不同编译器的代码,如果你这样做,我不会认为有任何一刀切的解决方案。
#1
2
As far as I can tell, GCC is very much dependent on the installation folder it was compiled for. I build RTEMS cross-compilation toolchains very frequently, and one of the first things I learned was that there are many places in the generated cross-compiler where the installation prefix (i.e. whatever was passed to --exec-prefix
) is "burned" in.
据我所知,GCC非常依赖于它编译的安装文件夹。我经常构建RTEMS交叉编译工具链,我学到的第一件事就是生成的交叉编译器中有很多地方安装前缀(即传递给--exec-prefix的任何内容)被“烧掉”在。
"Learned" - as in, I tried to move the compiler's folder to a different path, and all hell broke loose :-)
“学到了” - 就像在,我试图将编译器的文件夹移动到另一条路径,并且所有地狱都松了一口气:-)
My point: modifying specs
files to make them point to paths in your install seems absolutely normal, as far as GCC is concerned.
我的观点:就GCC而言,修改specs文件以使它们指向安装中的路径似乎绝对正常。
#2
0
When you’re compiling GCC, you need to pass the prefix you want to configure
anyway. At that time, you can also give it the --with-specs
option. Based on my experiments, the option --with-specs='%{!static:%x{-rpath='$prefix'/lib64} %x{-enable-new-dtags}}'
(where $prefix should be replaced by the same path you pass to
--prefix`) works (you need something more complicated for multilib support, of course).
在编译GCC时,无论如何都需要传递要配置的前缀。那时,你也可以给它--with-specs选项。根据我的实验,选项--with-specs ='%{!static:%x {-rpath ='$ prefix'/ lib64}%x {-enable-new-dtags}}'(其中$ prefix应该是替换为您传递给的相同路径 - 前缀`)工作(当然,您需要一些更复杂的multilib支持)。
Things to note:
注意事项:
- This isn’t properly documented anywhere, but it appears that, unlike with regular spec files, the
--with-specs
configure option applies to the command-line arguments passed to GCC itself. Thus, you can’t just try to modify the*link
spec string. - 这在任何地方都没有正确记录,但似乎与常规规范文件不同,--with-specs configure选项适用于传递给GCC本身的命令行参数。因此,您不能只是尝试修改* link规范字符串。
- The
%x
sequence doesn’t change the GCC command line, but accumulates arguments to pass to the linker. That’s why I pass-rpath
and-enable-new-dtags
directly instead of via-Wl
. - %x序列不会更改GCC命令行,但会累积参数以传递给链接器。这就是为什么我直接通过-rpath和-enable-new-dtags而不是通过-Wl。
- There are a bunch of suggestions online for what specs to pass. I didn’t see this one anywhere, so it take it with a grain of salt. The reason I used my own is that all the others either modify a spec string like
*link
, which you cannot do with--with-specs
, or they add options to the GCC command line using-Wl
, which I’m fairly sure somebody said they had trouble with because in some cases it confused GCC when they weren’t linking. YMMV. - 网上有很多建议可以通过哪些规范。我没有在任何地方看到这个,所以它带着一粒盐。我使用自己的原因是所有其他人都修改了像* link这样的规范字符串,你无法使用--with-specs,或者他们使用-Wl向GCC命令行添加选项,我很确定有人说他们有麻烦,因为在某些情况下,当他们没有链接时,它会混淆GCC。因人而异。
- If you use bootstrapping (which you usually are unless building a cross-compiler, in which case I could be wrong but I don’t think this particular rpath trick is useful anyway), this will add a
RUNPATH
to the GCC programs and shared libraries as well. This seems to be the correct option, because they were compiled against the libraries that are now in$prefix/lib64
, but it’s worth noting. - 如果你使用bootstrapping(除非你构建一个交叉编译器,你通常会这样做,在这种情况下我可能会错,但我不认为这个特殊的rpath技巧是有用的),这将为GCC程序和共享库添加一个RUNPATH同样。这似乎是正确的选项,因为它们是针对现在在$ prefix / lib64中的库编译的,但值得注意。
-
I added
-enable-new-dtags
, which puts this inDT_RUNPATH
instead ofDT_RPATH
. This is the newer attribute which all the documentation says should be preferred, <sarcasm>which is why it requires an extra flag which isn’t clearly cross-referenced in the docs</sarcasm>. Among the differences between RPATH and RUNPATH are:我添加了-enable-new-dtags,它将它放在DT_RUNPATH而不是DT_RPATH中。这是所有文档中应该首选的新属性,
这就是为什么它需要一个额外的标志,而这个标志在docs 中没有明确的交叉引用。 RPATH和RUNPATH之间的区别在于: - If RUNPATH is present, RPATH will be completely ignored.
- 如果存在RUNPATH,则将完全忽略RPATH。
- The RPATH overrides
LD_LIBRARY_PATH
; the RUNPATH does not. - RPATH覆盖LD_LIBRARY_PATH; RUNPATH没有。
- They work somewhat differently for dependencies of dependencies (
RUNPATH
is only searched for direct dependencies;RPATH
is searched for indirect dependencies as long as nothing in the dependency chain has aRUNPATH
). More details are available here. - 它们对依赖项的依赖性的工作方式有所不同(RUNPATH仅搜索直接依赖项;只要依赖项链中没有任何内容具有RUNPATH,就会搜索RPATH的间接依赖项)。更多细节可在此处获得。
- I think that’s everything, but I wouldn’t be surprised if I’m missing something.
- 我认为这就是一切,但如果我遗失了什么,我不会感到惊讶。
As the article I linked above indicates, not everybody prefers RUNPATH to RPATH, but here it shouldn’t be an issue unless you mix code from different compilers requiring different compiler support libraries in a complicated way, and if you do that I don’t think there’s any one-size-fits-all solution.
正如我在上面链接的文章所指出的那样,并不是每个人都喜欢RUNPATH到RPATH,但这里不应该是一个问题,除非你以复杂的方式混合需要不同编译器支持库的不同编译器的代码,如果你这样做,我不会认为有任何一刀切的解决方案。