Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb says "cannot open shared object file"

Tags:

c++

linux

emacs

gdb

I have one binary and one shared library. The shared library is compiled with:

all:
g++ -g -shared -fpic $(SOURCES) -o libmisc.so

the binary is compiled with:

LIBS=-L../../misc/src

LDFLAGS=-lmisc

all:
g++ -g -o mainx $(INCLUDE) $(SOURCE) $(LIBS) $(LDFLAGS)

I set in ~/.bashrc

export LD_LIBRARY_PATH=/mnt/sda5/Programming/misc/src/

to the libmisc.so output path.

Debugging from console works fine:

gdb mainx

However from Emacs22, launching gdb fails with the following message:

Starting program: /mnt/sda5/Programming/main/src/mainx /mnt/sda5/Programming/main/src/mainx: error while loading shared libraries: libmisc.so: cannot open shared object file: No such file or directory

This looks very tricky for the moment, and I couldn't solve it. I am not sure if this a emacs's problem, or I should pass a parameter in gdb's command line.

like image 744
grayasm Avatar asked May 31 '09 16:05

grayasm


3 Answers

Emacs probably does not read your .bashrc before it invokes gdb. Try to put 'set solib-search-path' and 'set solib-absolute-path in your .gdbinit file instead

like image 143
yhager Avatar answered Oct 19 '22 04:10

yhager


Another way is to create a .gdbinit file in your $HOME and set the LD_LIBRARY_PATH there:

# file .gdbinit
set env LD_LIBRARY_PATH=/mnt/sda5/Programming/misc/src/

This is convenient if you need to debug with that LD_LIBRARY_PATH frequently (and don't want to remember running emacs from your shell every time).

like image 36
Paul Avatar answered Oct 19 '22 05:10

Paul


Emacs doesn't invoke gdb via bash, but rather invokes it directly, and so .bashrc changes do not take effect and LD_LIBRARY_PATH is not set.

If you quit emacs, open a new shell (so LD_LIBRARY_PATH is set), start emacs in it, and then do M-X gdb, then it would work.

Setting solib-search-path in GDB is a hack.

A much better fix is to build the executable in such a way that it doesn't need LD_LIBRARY_PATH to begin with:

LDFLAGS=-lmisc -Wl,-rpath=/mnt/sda5/Programming/misc/src
like image 33
Employed Russian Avatar answered Oct 19 '22 04:10

Employed Russian