重定位错误,segfault,在另一台机器上运行程序时

时间:2013-12-23 21:46:23

标签: c++ ld

我正在尝试在我的大学的计算机上运行可执行程序,该程序在我的计算机上运行正常。那台计算机缺少一个编译器,还有我需要的库,例如boost libs。

所以我在我的计算机上编译了程序,并使用ldd / objdump将二进制文件和我能找到的所有库复制到另一台计算机上。不幸的是,在运行它时,链接器无法启动程序:

LD_LIBRARY_PATH="." ./my_program
./my_program: relocation error: ./libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference

当然我在网上搜索:当使用某个库的错误版本时,似乎会发生重定位错误。但是,当我提供编译期间存在的完全相同的库时,我无法看到这是如何实现的。

I read LD_BIND_NOW可用于调试动态链接;使用它,程序会立即发生段错误。我编译了一个-Og -ggdb的版本,在服务器上执行它并将生成的核心转储下载到我的计算机上(另一台计算机上也没有gdb)。这是会议:

$ gdb ./my_program core
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /my_program...done.

warning: core file may not match specified executable file.
[New LWP 8912]

warning: Can't read pathname for load map: Input/output error.

warning: .dynamic section for "/lib64/ld-linux-x86-64.so.2" is not at the expected address (wrong library or version mismatch?)

warning: Could not load shared library symbols for 14 libraries, e.g. ./libboost_program_options.so.1.54.0.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `./my_program'.
Program terminated with signal 11, Segmentation fault.
#0  0x00000000000056f6 in ?? ()
(gdb) bt
#0  0x00000000000056f6 in ?? ()
#1  0x00007f51ff6fff99 in ?? ()
#2  0x00007ffffb653480 in ?? ()
#3  0x00007f520069bc11 in _dl_relocate_object () from /lib64/ld-linux-x86-64.so.2
#4  0x00007f52006937b1 in dl_main () from /lib64/ld-linux-x86-64.so.2
#5  0x00007f52006a4dde in _dl_load_cache_lookup () from /lib64/ld-linux-x86-64.so.2
#6  0x0000000000000000 in ?? ()
(gdb)

此时我真的不知道该怎么办。我欢迎任何建议。谢谢!

PS:编译标志看起来像这样(我还尝试了在目标机器上使用-march = native的标志):

/usr/bin/c++ \
-Wall -Wextra -Woverloaded-virtual -Wpedantic -std=c++11 -pthread -Og -ggdb \
-Wl,--warn-unresolved-symbols,--warn-once ... -o my_program \
-rdynamic -lboost_program_options -lboost_system -lboost_filesystem -lboost_regex

0 个答案:

没有答案