修改g ++库路径 [英] Modify g++ library path
问题描述
搜索路径的输出:
$ b我最近安装了gcc 4.9.2,并在与libs链接时发现问题。 $ b
install:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/
programs:= / usr / libexec / gcc / x86_64 -Unknown-Linux的GNU / 4.9.2 /:在/ usr /的libexec / GCC / x86_64的未知-Linux的GNU / 4.9.2 /:在/ usr /的libexec / GCC / x86_64的未知-Linux的GNU /:在/ usr /lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9 0.2 /../../../../ x86_64的未知-Linux的GNU /斌/ x86_64的未知-Linux的GNU / 4.9.2 /:/ usr / lib中/ GCC / x86_64的未知Linux的-gnu / 4.9.2 /../../../../ x86_64的未知-Linux的GNU /斌/ x86_64的-Linux的GNU /:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU /4.9.2/../../../../x86_64-unknown-linux-gnu/bin/
libraries:= / usr / lib / gcc / x86_64-unknown-linux-gnu / 4.9 0.2 /:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU / 4.9.2 /../../../../ x86_64的未知-Linux的GNU / LIB / x86_64的未知Linux的-gnu / 4.9.2 /:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU / 4.9.2 /../../../../ x86_64的-不明正Linux的GNU / LIB / x86_64的-Linux的GNU /:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU / 4.9.2 /../../../../ x86_64的-unknown- Linux的GNU / lib中/../ lib64下/:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU / 4.9.2 /../../../ x86_64的未知-Linux的GNU / 4.9。 2 /:/ usr / lib中/ GCC / x86_64的未知-Linux的GNU / 4.9.2 /../../../ x86_64的-Linux的GNU /:/ usr / lib中/ GCC / x86_64的未知Linux的-gnu / 4.9.2 /../../../../ lib64下/:/ LIB / x86_64的未知-Linux的GNU / 4.9.2 /:/ LIB / x86_64的-Linux的GNU /:/ lib中/../lib64/:/usr/lib/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/usr /lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/:/usr/lib/gcc/x86_64-unknown -linux-gnu / 4.9.2 /../../../:/ lib /:/ usr / lib /
真的,有问题的是这样的:
$ p $ / usr / lib / x86_64-linux-gnu / :/ usr / lib /../ lib64 /
我需要改变这两个库的顺序(这样lib64具有更高的搜索优先级),因为两个dirs都有libstdc ++。so.6,我需要使用o ne在lib64文件夹中。
我该怎么做?
请不要:
1,建议我更改LD_LIBRARY_PATH以明确包含libstdc ++。so.6,因为我确定x86_64-linux-gnu文件夹中有其他的东西,它们的旧版本lib64文件夹 - 我从旧版本升级了g ++。
2,建议我在g ++ -L选项中明确包含lib64 / libstdc ++。so.6。 p>
非常感谢。
/ ***************** *******编辑更多信息************************ /
根据下面的请求,这里有一些关于配置和安装的更多细节(我从gcc.gnu.org下载了4.9.2源代码,解压并从4.9.2顶层文件夹开始):
mkdir ../gcc-build&&
cd ../gcc-build&&
../gcc-4.9.2/configure \
--prefix = / usr \
--libdir = / usr / lib \
--enable-shared \
--enable-threads = posix \
--enable -__ cxa_atexit \
--disable-multilib \
--with- system-zlib \
--enable-languages = c,c ++&&
make
或修改现有的)GCC specs
文件,文档是 here。
AFAIK, specs
文件位于您的安装 dir,因此你可以在 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/specs
(你可以创建如果它不存在)。
AFAIK有一些内置的默认设置,但您可以配置您的系统有一个明确的默认设置。
阅读有关调试选项的GCC。您可能希望使用 -dumpspecs
来获取内置的默认规格。
详细信息可能非常具体您的系统,特别是如果您从其源代码编译 GCC 。
我对 specs
文件不够熟悉,以便为您的特定问题提供可靠的解决方案。您可以在 gcc-help@gcc.gnu.org
上询问详情。
注意:我倾向于认为使用 - prefix = / usr $ c配置
gcc
$ c>(而不是非系统前缀,比如默认的 --prefix = / usr / local /
或者一些 --prefix = / opt /
etc ...)是一个错误(或者至少也使用 - program-suffix = -4.9
)。您可能会将 gcc
与系统 gcc
混合;如果您想替换您的系统 gcc
(这可能很危险),您应该配置新的 gcc
与系统 gcc
具有相同的参数。请注意, / usr / bin / gcc -v
会告诉您系统如何配置(在覆盖之前完成) gcc
当在一些较旧的系统上编译最近的GCC 4.9时,我通常会建议使用 - prefix = / usr / local来配置它。 /
和 - 程序后缀= -4.9
然后添加 / usr / local / bin /
添加到 $ PATH
中,并使用 make CC = gcc-4.9 CXX = g ++ - 4.9
它。
I recently installed gcc 4.9.2 and found a problem when linking with libs.
The output for search path:
install: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/
programs: =/usr/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/libexec/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/../lib64/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/:/lib/x86_64-unknown-linux-gnu/4.9.2/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-unknown-linux-gnu/4.9.2/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../x86_64-unknown-linux-gnu/lib/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../:/lib/:/usr/lib/
Really, the problematic thing is this:
/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib64/
I need to change the order of these two libs(so that lib64 has higher search priority), because both dirs have the libstdc++.so.6, and I need to use the one in lib64 folder.
How do I do it?
Please don't:
1, suggest that I change LD_LIBRARY_PATH to explicitly include libstdc++.so.6 as I'm sure there are other things in x86_64-linux-gnu folder that are older versions of that in the lib64 folder - I upgraded g++ from an older version.
2, suggest that I explicitly include that lib64/libstdc++.so.6 in the g++ -L option.
Thanks a lot.
/************************EDIT FOR MORE INFO************************/
Upon the request below, here're some more details about configuration and installation(I downloaded 4.9.2 source from gcc.gnu.org, extracted it and started in the 4.9.2 top level folder):
mkdir ../gcc-build &&
cd ../gcc-build &&
../gcc-4.9.2/configure \
--prefix=/usr \
--libdir=/usr/lib \
--enable-shared \
--enable-threads=posix \
--enable-__cxa_atexit \
--disable-multilib \
--with-system-zlib \
--enable-languages=c,c++ &&
make
You could have a new (or modify the existing) GCC specs
file, documentation is here.
AFAIK, the specs
file is in your "install" dir, so for you would be in
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/specs
(which you could create if it does not exist).
AFAIK there is some built-in default, but you could configure your system to have an explicit one.
Read also about the debugging options of GCC. You may want to use -dumpspecs
to get the built-in default spec.
Details may be highly specific to your system, especially if you compiled GCC from its source code.
I am not familiar enough with specs
files to give a reliable solution for your particular issue. You might ask on gcc-help@gcc.gnu.org
for details.
NB: I would tend to believe that configuring a gcc
with --prefix=/usr
(and not a non-system prefix like the default --prefix=/usr/local/
or some --prefix=/opt/
etc...) is a mistake (or at least use also --program-suffix=-4.9
). You are likely to mix up your gcc
with the system gcc
; If you want to replace your system gcc
(which is probably dangerous) you should configure your new gcc
with the same arguments as your system gcc
had. Notice that /usr/bin/gcc -v
tells you how was your system gcc
configured (to be done before overwriting it).
When compiling a recent GCC 4.9 on some older system I generally would recommend to configure it with --prefix=/usr/local/
and --program-suffix=-4.9
then add /usr/local/bin/
to your $PATH
, and use make CC=gcc-4.9 CXX=g++-4.9
for building programs with it.
这篇关于修改g ++库路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!