Author Topic: GDB from CB can't find shared object file after linking ok  (Read 5545 times)

Offline Napoleon

  • Multiple posting newcomer
  • *
  • Posts: 59
GDB from CB can't find shared object file after linking ok
« on: October 18, 2014, 04:54:19 pm »
In my current project, I have added a custom shared library "libr2d2" to the "Build Options (Debug)->Linker Settings"  tab on the LHS.  On the RHS of that same tab, I put in "-L /path/to/my/library/".  The library was built with debug symbols.
When I build the project I'm currently working on, it succeeds and places an executable into the Debug folder.  If I run the executable (or debug it using GDB) from a separate terminal window, it works fine.

However, when I debug from Code::Blocks using the red 'play' button, the output terminal window flashes up with the following message and disappears (even through my terminal preferences are set to keep it open on exit).  Putting a breakpoint on the first instruction in my 'main' procedure doesn't stop it either.
Code
/media/Data/DJ/projects/robot/bin/Debug/controller: error while loading shared libraries:  libr2d2.so: cannot open shared object file: No such file or directory

I tried moving the library from the external drive to my home folder but that didn't help.

Debugger window output below:
Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /media/Data/DJ/projects/robot/
Adding source dir: /media/Data/DJ/projects/robot/
Adding file: /media/Data/DJ/projects/robot/bin/Debug/controller
Changing directory to: /media/Data/DJ/projects/robot/.
Set variable: LD_LIBRARY_PATH=.:

[debug]Command-line: /usr/bin/gdb -nx -fullname  -quiet  -args /media/Data/DJ/projects/robot/bin/Debug/controller
[debug]Working dir : /media/Data/DJ/projects/robot

Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /media/Data/DJ/projects/robot/bin/Debug/controller
done

[debug]Reading symbols from /media/Data/DJ/projects/robot/bin/Debug/controller...done.
[debug](gdb)
[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]>>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.1-ubuntu
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-linux-gnu".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.1-ubuntu

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source /usr/local/share/codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory /media/Data/DJ/projects/robot/
[debug]Source directories searched: /media/Data/DJ/projects/robot:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "/media/Data/DJ/projects/robot/src/avoid.cpp:26"
[debug]Breakpoint 4 at 0x4011a5: file /media/Data/DJ/projects/robot/src/avoid.cpp, line 26.
[debug]>>>>>>cb_gdb:
[debug]> break "/media/Data/DJ/projects/robot/src/avoid.cpp:9"
[debug]Breakpoint 5 at 0x40115c: file /media/Data/DJ/projects/robot/src/avoid.cpp, line 9.
[debug]>>>>>>cb_gdb:
[debug]> break "/media/Data/DJ/projects/robot/src/avoid.cpp:29"
[debug]Note: breakpoint 4 also set at pc 0x4011a5.
[debug]Breakpoint 6 at 0x4011a5: file /media/Data/DJ/projects/robot/src/avoid.cpp, line 29.
[debug]>>>>>>cb_gdb:
[debug]> break "/media/Data/DJ/projects/robot/src/avoid.cpp:12"
[debug]Note: breakpoint 5 also set at pc 0x40115c.
[debug]Breakpoint 7 at 0x40115c: file /media/Data/DJ/projects/robot/src/avoid.cpp, line 12.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/pts/6
[debug]Queued:[tty /dev/pts/6]
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /media/Data/DJ/projects/robot/bin/Debug/controller
[debug][Inferior 1 (process 32255) exited with code 0177]
[debug]>>>>>>cb_gdb:

[Inferior 1 (process 32255) exited with code 0177]

[debug]> quit

Debugger finished with status 0

I have added libraries to my projects before without this happening so I'm stumped.  Can anyone explain what's going on, please?

Offline Napoleon

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: GDB from CB can't find shared object file after linking ok
« Reply #1 on: October 19, 2014, 04:50:53 am »
Never mind,  this problem is also occurring from the terminal window.

UPDATE
Originally I fixed this problem by putting the library in question into a folder that Linux searches (ie /usr/local/lib ).
However, I'm now referencing a library that I can't just move or symlink to.  So I tried a few other things.  Below is a SOLUTION, but not an optimal one.  Perhaps someone who knows CB better than I can improve this method.

Go to Settings->Environment->Environment Variables
Press the ADD button near the bottom.
Fill out the dialog with the following:
   Key:  LD_LIBRARY_PATH
   Value: $LD_LIBRARY_PATH:/path/to/my/library:/path/to/other/libraries  (etc)

The reasons for asking for an improvement is that (1) this gave me a override warning, which I accepted, (2) this is not a 'per project' solution, (3) It has the means to apply a bunch of other environment variables, if set, which could be either good or bad, depending on how you're using it.

Cheers,
Nap
« Last Edit: October 24, 2014, 06:13:59 pm by Napoleon »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: GDB from CB can't find shared object file after linking ok
« Reply #2 on: November 02, 2014, 05:15:43 am »
Did you try the normal way to see if it works? I do NOT use the debugger very much; so, I have no idea if it works or not.

Project -> Build Options

Tab: Search Directories
Sub-Tab: Linker
  Enter the path that holds the library

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org