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.
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
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With