在/ usr / local / lib目录库未找到 [英] Libraries in /usr/local/lib not found

查看:224
本文介绍了在/ usr / local / lib目录库未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用一种称为 ohNet 框架的应用程序。
建设框架后,是安装通过框架使得安装的可能性。默认情况下安装在库中的的/ usr /本地/内部[LIB |列入] 文件夹。 ok了。

I am building an application using a framework called ohNet. After building the framework, there is the possibility to install the framework via make install. By default the libraries are installed inside the /usr/local/[lib|include] folders. ok.

我使用Eclipse进行开发。为了使用这个库,我必须设置包含路径库(在这种情况下 USR /本地/包括/ ohNet ),设置连接器搜索路径(-L )(的/ usr / local / lib目录/ ohNet )和特定的库(-l)(在这种情况下,我选择了一个名为库 libohNet.so 其中的此文件夹中。
当我建立这个项目在eclipse它工作正常,但是如果我尝试运行我面对以下消息PROGRAMM:

I am using eclipse for development. In order to use this libraries I have to set the include path to the library (in this case usr/local/include/ohNet), set the Linker search path (-L)(/usr/local/lib/ohNet) and specific libraries (-l) (in this case i choose a library called libohNet.so which is in this folder. When I build the project in eclipse it works fine, however if i try to run the programm i am faced with the following message:

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

我仔细检查过这一点,文件 libohNet.so 此目录中!
那是什么这个文件不能被发现的原因?

I've double checked this, and the file libohNet.so is in this directory! What's the reason that this file cannot be found?

我搜索谷歌和发现了一些帖子,说是有问题的,图书馆越来越安装到的/ usr / local / lib目录而不是 / usr / lib目录 see这里 ...
我一定要蚀配置一些额外的设置,使 LD 识别此路径库?什么是解决此?

I searched on google and found some posts, saying that it is problematic that libraries are getting installed into /usr/local/lib instead of /usr/lib see here ... Do I have to configure some additional settings in eclipse to make ld recognize libraries in this path? What's the solution for this?

关于

推荐答案

这是一个运行时错误,而不是生成错误。设置 -L 标志无助的运行时链接。你需要做的就是告诉运行时加载器也期待在/ usr / local / lib目录图书馆。你可以这样做有两种方式。首先是路径添加到 LD_LIBRARY_PATH 环境变量:

This is a runtime error, not a build error. Setting the -L flag does nothing for the runtime linker. What you need to do is to tell the runtime loader to also look in /usr/local/lib for libraries. You can do that in two ways. The first is to add the path to the LD_LIBRARY_PATH environment variable:


export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

二是要更新运行时链接程序的配置文件。发生这种情况无论是在/etc/ld.so.conf中的文件,通过将行:

The second is to update the configuration file of the runtime linker. This can happen either in the /etc/ld.so.conf file, by putting the line:


/usr/local/lib

某处在该文件中,或者通过创建在包含新路径/etc/ld.so.conf.d/目录新* .conf文件。例如:

somewhere in that file, or by creating a new *.conf file in the /etc/ld.so.conf.d/ directory that contains the new path. For example:


/etc/ld.so.conf.d/99local.conf

只有


/usr/local/lib

在里面。这是这样做的推荐的方式,因为它可以让你保持你的自定义库的路径由系统设置的路径分开。 (99preFIX在那里,以确保文件被加载去年相比其他文件的存在,所以它不会preempt系统路径可能包含相同的库)。

in it. This is the recommended way of doing this, as it allows you to keep your custom library paths separate from paths set by the system. (The "99" prefix is there to make sure the file is loaded last compared to other files there, so that it won't preempt system paths that could contain the same libraries.)

您修改后/创建/ etc中的文件,你需要运行:

After you modify/create the file in /etc, you need to run:


ldconfig

为根,以使更改生效。 (该命令更新的文件/etc/ld.so.cache,这是由运行时链接程序使用的实际文件。)

as root for the change to take effect. (This command updates the /etc/ld.so.cache file, which is the actual file used by the runtime linker.)

还有另一种方式为二进制找到所需的库在运行时。实际上,你可以硬code库路径到可执行文件本身。这是通过设置一个所谓的rpath的完成的。这是一个连接器选项,必须从海湾合作委员会(或g ++)给连接器传递,因此 -Wl 选项已被使用。链接选项是 -rpath = PATH 。所以,你需要添加到您的链接标志:

There's also another way for a binary to find needed libraries at runtime. You can actually hard-code library paths into the executable itself. This is accomplished by setting a so called "rpath". This is a linker option and must be passed from gcc (or g++) to the linker, so the -Wl option has to be used. The linker option is -rpath=PATH. So you would need to add this to your link flags:


-Wl,-rpath=/usr/local/lib

我不尽管对于你的情况建议使用此。当你和你的可执行文件(可能使用安装程序)库船一起的rpath的是有用的,和相对rpath的(使用 rpath的$ ORIGIN 功能)或绝对的(当您安装在/ opt,例如)为随后用于在运行时发现这些捆绑库。

I don't recommend this for your case though. An rpath is useful when you're shipping libraries together with your executable (maybe with an installer), and a relative rpath (using the rpath $ORIGIN feature) or absolute one (for when you install in /opt, for example) is then used to find those bundled libs at runtime.

这篇关于在/ usr / local / lib目录库未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆