tags:

views:

952

answers:

2

Hello all, 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. Please share your ideas with me.

vmihai

+3  A: 

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

yhager
Thank you very much for your answer.It worked very well. I searched previously the gdb manual with key words to find a quick answer but I failed. You saved my day :)I will read of course the gdb manual in depth these days.vmihai.
grayasm
+1  A: 

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
Employed Russian
Not available on all platforms, and when it is, -rpath has it's problems too:[rpath(linking)](http://en.wikipedia.org/wiki/Rpath_(linking))It's always a tradeoff.
Don Wakefield
Thanks for the answer.That sounds reasonable also.
grayasm