C++ 如何为 GDB 加载额外的库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15049422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load extra libraries for GDB?
提问by Employed Russian
I'm trying to debug a CUDA program, but when I'm launching gdb
like so:
我正在尝试调试 CUDA 程序,但是当我gdb
像这样启动时:
$ gdb -i=mi <program name>
$ r <program arguments>
I'm getting:
我越来越:
/home/wvxvw/Projects/cuda/exercise-1-udacity/cs344/HW2/hw:
error while loading shared libraries: libcudart.so.5.0:
cannot open shared object file: No such file or directory
Process gdb-inferior killed
(formatted for readability)
(格式化以提高可读性)
(I'm running gdb using M-xgdb
) If that matters, then CUDA libraries are in the .bashrc
(我正在使用 gdb 运行M-xgdb
)如果这很重要,那么 CUDA 库就在.bashrc
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
回答by Employed Russian
error while loading shared libraries: libcudart.so.5.0
加载共享库时出错:libcudart.so.5.0
This error has nothing to do with GDB: your executable, when run from inside GDB, can't find the library it needs.
此错误与 GDB 无关:您的可执行文件从 GDB 内部运行时,找不到它需要的库。
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
导出 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
GDB runs your program in a new $SHELL
, so that should have worked. I wonder if there is some interaction with emacs.
GDB 在一个新的$SHELL
. 我想知道是否有一些与emacs的交互。
In any case, this:
无论如何,这是:
(gdb) set env LD_LIBRARY_PATH /usr/local/cuda/lib64
(gdb) run
should fix this problem.
应该解决这个问题。
Update:
更新:
as I've mentioned it before, ld path is set properly
正如我之前提到的,ld 路径设置正确
No, it isn't. If it was, you wouldn't have the problem.
不,它不是。如果是这样,你就不会有这个问题。
Now, I don't know whyit isn't set properly. If you really want to find out, start by running GDB outside emacs (to exclude possible emacs interactions).
现在,我不知道为什么它没有正确设置。如果您真的想找出答案,请首先在 emacs 之外运行 GDB(以排除可能的 emacs 交互)。
If the problem is still present, gdb show env
, shell env
, adding echo "Here"
to your ~/.basrc
, etc. should help you find where things are not working as you expect them.
如果问题仍然存在, gdb show env
、shell env
、 add echo "Here"
to your~/.basrc
等应该可以帮助您找到事情没有按预期工作的地方。
回答by Tim
I've had this problem as well. One way to look at it is that even if the LD_LIBRARY_PATH variable is correct when you enter show env
into gdb, it may not be correct when you actually execute the program because gdb executes $SHELL -c <program>
to run the program. Try this as a test, run $SHELL
from the command line and then echo $LD_LIBRARY_PATH
. Is it correct? If not, then you probably need to add it to your rc (.tcshrc in my case).
我也遇到过这个问题。一种看待方式是,即使进入show env
gdb时LD_LIBRARY_PATH变量是正确的,实际执行程序时也可能不正确,因为gdb是$SHELL -c <program>
为了运行程序而执行的。试试这个作为测试,从命令行运行$SHELL
,然后echo $LD_LIBRARY_PATH
. 这是正确的吗?如果没有,那么您可能需要将它添加到您的 rc(在我的情况下为 .tcshrc)。
回答by Joshua Brown
I had a similar problem when trying to run gdb on windows 7. I use MobaXterm to access a Linux toolbox. I installed gdb separately from http://www.gnu.org/software/gdb/. I got it to work by making sure gdb could find the correct .dll files as mentioned by Employed Russian. If you have MobaXterm installed the .dll files should appear in your home directory in MobaXterm/slash/bin.
我在 Windows 7 上尝试运行 gdb 时遇到了类似的问题。我使用 MobaXterm 访问 Linux 工具箱。我从http://www.gnu.org/software/gdb/单独安装了 gdb 。我通过确保 gdb 可以找到 Employed Russian 提到的正确 .dll 文件来使其工作。如果您安装了 MobaXterm,.dll 文件应该出现在您的主目录中的 MobaXterm/slash/bin 中。
gdb however did not recognize the LD_LIBRARY_PATH
variable. For me, it worked when I used the PATH variable instead:
然而,gdb 无法识别该LD_LIBRARY_PATH
变量。对我来说,当我使用 PATH 变量时它起作用了:
(gdb) set env PATH C:\Users\Joshua\Documents\MobaXterm\slash\bin
(gdb) run
I would think using PATH
instead of LD_LIBRARY_PATH
might work for you provided you put the correct path to your library.
如果您将正确的路径放入库,我认为使用PATH
而不是LD_LIBRARY_PATH
可能对您有用。
回答by anoneironaut
gdb is looking for a library, so why are you concerned with the include path? You may want to try to set the gdb option "solib-search-path" to point to the location of the libcudart.so.5.0 library.
gdb 正在寻找一个库,那么你为什么关心包含路径?您可能想尝试将 gdb 选项“solib-search-path”设置为指向 libcudart.so.5.0 库的位置。