问题
On Ubuntu, I have a C++ app in Eclipse. The application compiles fine and I can run the app from the command line.
But when I try to debug it or run it with Eclipse, the error :
"Cannot open shared object file: No such file or directory" is thrown on a shared library.
I've set LD_LIBRARY_PATH in my bashrc file and also set an LD_LIBRARY_PATH environment variable in both the Run Configuration and Debug Configuration to :
/home/behlingb/Documents/api_libs/FileGDB_API/lib
What else am I missing here to get Eclipse to run this?
UPDATE
There is only one shared object file this application requires, and that file is from a 3rd party API download. I just found that if I place the shared object inside the directory the executable is in, it will debug in Eclipse. Is there a way to specify a different directory so I dont have to copy the file for every project?
回答1:
I'm using the Kepler version of Eclipse.
- In Eclipse click on Run then Debug Configurations
- Click on the Environment Tab
- Click on New
- Add LD_LIBRARY_PATH and set its value to the directory containing the library
- restart Eclipse
回答2:
you can use strace utility (and then grep for open and/or stat calls) to get list of .so files required to run smth, then use locate (or find among packages) to find out the actual placement of required lib
回答3:
According to what @zuafi suggested , you do not have to grep for the libraries and `locate' to find them.
Instead save strace's output to a file:
strace -o my_output_file.txt /path/to/my_executable_file
then open the file, where you can see
open("/a/path/to/some/library.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
scroll down those lines until you hit
open("/real/path/to/some/library.so", O_RDONLY|O_CLOEXEC) = 3 (any value here)
this means before finding /real/path/to/some/library.so there have been several trials to find library.so in different paths. but finally the library has been found in /real/path/to/some/.
Just copy and paste this into your Eclipse!
回答4:
If you have set LD_LIBRARY_PATH and it doesn't work. Close Eclipes and run it from command terminal. I accidentally found that this could make it work. Not sure about the reason, but probably have something to do with Eclipes initialization.
回答5:
This is valid with Eclipse Kepler (I have not looked into older versions). To enable the debugger to load your shared libraries, trying to set LD_LIBRARY_PATH will fail. However the CDT plugin provides a Shared Libraries list for this purpose
Run menu -> Debug Configurations ...
then in the configuration dialog
C/C++ Application -> your project -> Debugger tab -> Shared Libraries tab
来源:https://stackoverflow.com/questions/14448343/cannot-open-shared-object-file-no-such-file-or-directory-running-or-debugging