程序找不到glibc / libstdc ++的正确版本,尽管它是静态链接的 [英] The program cannot find correct version of glibc/libstdc++, although it was statically linked
问题描述
我试图用glibc静态链接我的程序,因为目标机器上的glibc版本几乎不可预知。我使用链接器标志-static-libgcc和-static-libstdc ++,它工作正常。可执行文件很大,但我可以忍受它。不幸的是,当我在目标机器上运行我的可执行文件(它在下面的例子中被命名为'mytest')时,出现以下错误:
./ mytest:/usr/lib64/libstdc++.so.6:找不到版本'GLIBCXX_3.4.11'(需要libboost_log.so.1.53.0)
./mytest:/ usr / lib64 / libstdc ++。so.6:未找到'GLIBCXX_3.4.15'版本(libboost_log.so.1.53.0要求)
./mytest:/usr/lib64/libstdc++.so.6:版本'GLIBCXX_3.4.9'找不到(libboost_log.so.1.53.0要求)
./mytest:/usr/lib64/libstdc++.so.6:找不到版本'GLIBCXX_3.4.15'(需要libboost_date_time.so.1.53.0 )
./mytest:/usr/lib64/libstdc++.so.6:未找到'GLIBCXX_3.4.9'版本(libboost_thread.so.1.53.0要求)
如果我在mytest上使用'strings',它会给我
$ strings mytest | grep GLIBC
GLIBC_2.9
GLIBC_2.7
GLIBC_2.8
GLIBC_2.3.2
GLIBC_2.2.5
GLIBCXX_3.4.15
GLIBCXX_3。 4.11
GLIBCXX_3.4.14
GLIBCXX_3.4.9
GLIBCXX_3.4
我认为,这意味着静态链接工作正常。为什么加载器仍然试图在共享的glibc和libstdc ++中查找我的函数?
谢谢!
我试图用glibc静态链接我的程序,因为目标机器上的glibc版本几乎不可预知。我使用了链接器标志-static-libgcc和-static-libstdc ++,它工作正常。
这并不影响glibc的版本( libc
),与 libgcc
和 libstdc ++不同
。有了这些标志,您仍然生成了一个动态链接的可执行文件,这是期望的不能用于较早的发行版。
您可以链接你的可执行文件使用 -static
标志,并且应该给你一个完全静态的可执行文件。
更新:
重新阅读您的问题后,你的问题是不是, glibc
。你的问题是你正在链接 libboost_log.so
,它本身依赖于 libstdc ++。so.6
。 p>
然后答案是与 libboost * .a
而不是 libboost * .so
。你可以尝试这样做:
g ++ $(OBJS)-static-libgcc -static-libstdc ++ -Wl, - Bstatic -lboost_log ... \
-Wl,-Bdynamic
em> 对于 -Wl,-Bdynamic
来说很重要。)
I am trying to link my program statically with glibc, because version of the glibc on the target machine is pretty much unpredictable. I used linker flags -static-libgcc and -static-libstdc++ and it worked fine. The executable is big, but I can live with it. Unfortunately, when I run my executable on the target machine (it is named 'mytest' in the example below) I get the following error:
./mytest: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by libboost_log.so.1.53.0)
./mytest: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by libboost_log.so.1.53.0)
./mytest: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by libboost_log.so.1.53.0)
./mytest: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by libboost_date_time.so.1.53.0)
./mytest: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by libboost_thread.so.1.53.0)
If I do 'strings' on mytest, it gives me
$ strings mytest | grep GLIBC
GLIBC_2.9
GLIBC_2.7
GLIBC_2.8
GLIBC_2.3.2
GLIBC_2.2.5
GLIBCXX_3.4.15
GLIBCXX_3.4.11
GLIBCXX_3.4.14
GLIBCXX_3.4.9
GLIBCXX_3.4
What means, I think, that the static linking was working ok. Why does the loader still tries to look for my functions in shared glibc and libstdc++? What am I doing wrong?
Thanks!
I am trying to link my program statically with glibc, because version of the glibc on the target machine is pretty much unpredictable. I used linker flags -static-libgcc and -static-libstdc++ and it worked fine.
That didn't affect the version of glibc (libc
), which is different from libgcc
and libstdc++
. With these flags, you still have produced a dynamically-linked executable, which is expected to not work on an older distribution.
You can link your executable with -static
flag, and that should give you a completely static executable.
Update:
After re-reading your question; your problem is not with glibc
. Your problem is that you are linking with libboost_log.so
, which itself depends on libstdc++.so.6
.
The answer then is to link with libboost*.a
instead of libboost*.so
. You can try to achieve it this way:
g++ $(OBJS) -static-libgcc -static-libstdc++ -Wl,-Bstatic -lboost_log ... \
-Wl,-Bdynamic
(It is very important to have the trailing -Wl,-Bdynamic
.)
这篇关于程序找不到glibc / libstdc ++的正确版本,尽管它是静态链接的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!