Eclipse CDT 自动包含共享库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5327744/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:00:32  来源:igfitidea点击:

Eclipse CDT Auto Include Shared Libraries

c++eclipseg++shared-librarieseclipse-cdt

提问by James

I am working in Eclipse: Helios Service Release 1 using Eclipse CDT compiling using g++

我在 Eclipse 中工作:Helios Service Release 1 using Eclipse CDT compile 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.

我刚刚开始尝试在我的项目中使用共享库,但遇到了一个小问题。我有三个项目 A、B 和 C。A 和 B 都是共享库,C 是可执行文件。

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:

在 Eclipse 下,我设法从 C 和 C 中引用 A 和 B 编译并正确运行,但是当我尝试在 Eclipse 之外手动运行生成的 C 程序时,出现以下错误:

"error while loading shared libraries: libA.so: cannot open shared object file: No such file or directory"

加载共享库时出错:libA.so:无法打开共享对象文件:没有这样的文件或目录

I have tried moving A.so B.so and C into the same folder and run C but I get the same error.

我曾尝试将 A.so B.so 和 C 移动到同一个文件夹中并运行 C,但我遇到了同样的错误。

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?

我是否可以让 Eclipse 使用同一位置的所有文件构建我的项目,并且当我将它们移动到新位置时它们仍然运行?

回答by Tim ?as

Run ldconfigas root to update the cache - if that still doesn't help, you need to add the path to the file ld.so.conf(just type it in on its own line) or better yet, add the entry to a new file (easier to delete) in directory ld.so.conf.d.

ldconfig以 root 身份运行以更新缓存 - 如果这仍然没有帮助,您需要添加文件路径ld.so.conf(只需在其自己的行中输入)或者更好的是,将条目添加到新文件(更容易删除) ) 在目录中ld.so.conf.d

回答by v01d

You just need to set LD_LIBRARY_PATHto include the folder in which the shared libraries are. Something like this: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/lib/

您只需要设置LD_LIBRARY_PATH为包含共享库所在的文件夹。像这样的东西:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/lib/