GDB“无法打开共享对象文件"问题 [英] GDB "cannot open shared object file" Issue

查看:40
本文介绍了GDB“无法打开共享对象文件"问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了 gdb 说无法打开共享对象文件";gdb 无法打开共享对象文件 并跟随说明.

I've already read gdb says "cannot open shared object file" and gdb can not open shared object file and followed the instructions.

我有一个链接到共享库文件 (/zzz/yyy/xxx.so) 的二进制文件.在我将 LD_LIBRARY_PATH 设置为 /zzz/yyy/ 并在没有 GDB 的情况下运行二进制文件后,它执行得非常好.

I have a binary which is linked to a shared library file (/zzz/yyy/xxx.so). After I set LD_LIBRARY_PATH to /zzz/yyy/ and run the binary without GDB, it executes very well.

但是,当我尝试使用 GDB 调试这个二进制文件时,GDB 说:

However, when I was trying to use GDB to debug this binary, GDB says:

加载共享库时出错:xxx.so: cannot open shared object file: No such file or directory

我已经有了(在 .gdbinit 中设置):

I already have (set in .gdbinit):

(gdb)show env LD_LIBRARY_PATH
LD_LIBRARY_PATH = "/zzz/yyy/"

(gdb) show solib-search-path
The search path for loading non-absolute shared library symbol files is "/zzz/yyy/".

在我的系统中:

% printenv LD_LIBRARY_PATH
/zzz/yyy

GDB 仍然找不到这个共享库的其他可能原因是什么?

What's the other possible reasons why GDB still can't find this shared library?

推荐答案

但是,当我尝试使用 GDB 调试此二进制文件时,GDB 显示:加载共享库时出错:xxx.so:无法打开共享对象文件:没有这样的文件或目录

However, when I was trying to use GDB to debug this binary, GDB says: error while loading shared libraries: xxx.so: cannot open shared object file: No such file or directory

你错了:不是 GDB 这么说的,而是动态加载器.GDB 本身并不关心 LD_LIBRARY_PATH 的设置,它只是运行您的程序.但是你的程序无法运行.

You are mistaken: it's not GDB that says that, it's the dynamic loader. GDB itself doesn't care what LD_LIBRARY_PATH is set to, it simply runs your program. But your program can not run.

最常见的原因:您在 ~/.cshrc 中重新设置了 LD_LIBRARY_PATH,而 GDB 在单独的 shell 中运行您的程序,并且该 shell 读取你的 .cshrc,所以你的程序在不正确的环境下执行.

The most common cause: you are re-setting your LD_LIBRARY_PATH in your ~/.cshrc, and GDB runs your program in a separate shell, and that shell reads your .cshrc, so your program executes with incorrect environment.

解决方法是让 .cshrc not 为非交互式 shell 设置 LD_LIBRARY_PATH.参见例如这个答案.

The fix is to make .cshrc not set LD_LIBRARY_PATH for non-interactive shells. See e.g. this answer.

这篇关于GDB“无法打开共享对象文件"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆