6

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.

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
5

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

2 Comments

Not available on all platforms, and when it is, -rpath has it's problems too: rpath(linking) It's always a tradeoff.
Thanks for the answer. That sounds reasonable also.
5

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.