Cannot open shared object file: No such file or directory; Running or Debugging in Eclipse

帅比萌擦擦* 提交于 2019-12-30 04:11:09

问题


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.

  1. In Eclipse click on Run then Debug Configurations
  2. Click on the Environment Tab
  3. Click on New
  4. Add LD_LIBRARY_PATH and set its value to the directory containing the library
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!