Eclipse CDT 自动包含共享库
我正在 Eclipse 中工作:Helios Service Release 1 使用 Eclipse CDT 使用 g++ 进行编译
我刚刚开始尝试在我的项目中使用共享库,但遇到了一个小问题。我有三个项目 A、B 和 C。A 和 B 都是共享库,C 是可执行文件。
在 Eclipse 下,我成功地从 C 引用了 A 和 B,C 编译并正确运行,但是当我尝试在 Eclipse 之外手动运行生成的 C 程序时,出现以下错误:
“加载共享库时出错:libA. so: 无法打开共享对象文件: 没有这样的文件或目录”
我尝试将 A.so B.so 和 C 移动到同一文件夹中并运行 C,但出现相同的错误。
我可以让 Eclipse 构建我的项目并将所有文件放在同一个位置,并且当我将它们移动到新位置时它们仍然运行吗?
I am working in Eclipse: Helios Service Release 1 using Eclipse CDT compiling using g++
I have just started to have a go at using Shared Libraries in my projects but have run into a little problem. I have three projects A, B and C. A and B are both Shared Libraries and C is an executable.
Under eclipse I have managed to reference A and B from C and C compiles and runs correctly but when I try and run the generated C program manually outside of Eclipse I get the following error:
"error while loading shared libraries: libA.so: cannot open shared object file: No such file or directory"
I have tried moving A.so B.so and C into the same folder and run C but I get the same error.
Can I get Eclipse to build my project with all the files in the same place and them still run when I move them to a new location?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以 root 身份运行 ldconfig 来更新缓存 - 如果仍然没有帮助,您需要添加文件 ld.so.conf 的路径(只需将其键入在其自己的行中)或者更好的是,将条目添加到目录 ld.so.conf.d 中的新文件(更容易删除)。
Run
ldconfig
as root to update the cache - if that still doesn't help, you need to add the path to the fileld.so.conf
(just type it in on its own line) or better yet, add the entry to a new file (easier to delete) in directoryld.so.conf.d
.您只需设置 LD_LIBRARY_PATH 即可包含共享库所在的文件夹。
像这样的东西:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/lib/
You just need to set
LD_LIBRARY_PATH
to include the folder in which the shared libraries are.Something like this:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/lib/