无法打开共享对象文件:没有那个文件或目录;在 Eclipse 中运行或调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14448343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open shared object file: No such file or directory; Running or Debugging in Eclipse
提问by user714157
On Ubuntu, I have a C++ app in Eclipse. The application compiles fine and I can run the app from the command line.
在 Ubuntu 上,我在 Eclipse 中有一个 C++ 应用程序。该应用程序编译良好,我可以从命令行运行该应用程序。
But when I try to debug it or run it with Eclipse, the error :
但是当我尝试调试它或使用 Eclipse 运行它时,错误:
"Cannot open shared object file: No such file or directory"
is thrown on a shared library.
"Cannot open shared object file: No such file or directory"
被抛出到共享库上。
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 :
我已经在我的 bashrc 文件中设置了 LD_LIBRARY_PATH 并且还在运行配置和调试配置中设置了一个 LD_LIBRARY_PATH 环境变量:
/home/behlingb/Documents/api_libs/FileGDB_API/lib
/home/behlingb/Documents/api_libs/FileGDB_API/lib
What else am I missing here to get Eclipse to run this?
为了让 Eclipse 运行它,我还缺少什么?
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?
此应用程序只需要一个共享对象文件,该文件来自 3rd 方 API 下载。我刚刚发现,如果我将共享对象放在可执行文件所在的目录中,它将在 Eclipse 中进行调试。有没有办法指定不同的目录,这样我就不必为每个项目复制文件?
回答by monzie
I'm using the Kepler version of Eclipse.
我正在使用 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
- 在 Eclipse 中点击运行然后调试配置
- 单击环境选项卡
- 点击新建
- 添加 LD_LIBRARY_PATH 并将其值设置为包含库的目录
- 重启 Eclipse
回答by zaufi
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
您可以使用strace
实用程序(然后使用grep
foropen
和/或stat
调用)来获取运行 smth 所需的 .so 文件列表,然后使用locate
(或在包中查找)找出所需库的实际位置
回答by sali
According to what @zuafi suggested , you do not have to grep for the libraries and `locate' to find them.
根据@zuafi 的建议,您不必对库进行 grep 并通过“定位”来找到它们。
Instead save strace's output to a file:
而是将 strace 的输出保存到文件中:
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/
.
这意味着在找到之前/real/path/to/some/library.so
,已经library.so
在不同的路径中进行了多次尝试。但最终图书馆已在/real/path/to/some/
.
Just copy and paste this into your Eclipse!
只需将其复制并粘贴到您的 Eclipse 中即可!
回答by Northern
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.
如果你已经设置LD_LIBRARY_PATH
,它不起作用。关闭 Eclipes 并从命令终端运行它。我偶然发现这可以使它工作。不确定原因,但可能与 Eclipes 初始化有关。
回答by zeFrenchy
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 Librarieslist for this purpose
这对 Eclipse Kepler 有效(我没有研究过旧版本)。要使调试器能够加载您的共享库,尝试设置 LD_LIBRARY_PATH 将失败。但是 CDT 插件为此提供了一个共享库列表
Runmenu -> Debug Configurations ...
运行菜单 ->调试配置...
then in the configuration dialog
然后在配置对话框中
C/C++ Application-> your project-> Debuggertab -> Shared Librariestab
C/C++ 应用程序->您的项目->调试器选项卡 ->共享库选项卡