`
guoyiqi
  • 浏览: 968282 次
社区版块
存档分类
最新评论

(转)/etc/ld.so.conf和ldconfig, PKG_CONFIG_PATH

 
阅读更多

http://dev.firnow.com/course/6_system/linux/Linuxjs/200874/130190.html

首先说下/etc/ld.so.conf:

这个文件记录了编译时使用的动态链接库的路径。
默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件
如果你安装了某些库,比如在安装gtk+-2.4.13时它会需要glib-2.0 >= 2.4.0,辛苦的安装好glib后
没有指定 --prefix=/usr 这样glib库就装到了/usr/local下,而又没有在/etc/ld.so.conf中添加/usr/local/lib
这个搜索路径,所以编译gtk+-2.4.13就会出错了
对于这种情况有两种方法解决:
一:在编译glib-2.4.x时,指定安装到/usr下,这样库文件就会放在/usr/lib中,gtk就不会找不到需要的库文件了
对于安装库文件来说,这是个好办法,这样也不用设置PKG_CONFIG_PATH了 (稍后说明)

二:将/usr/local/lib加入到/etc/ld.so.conf中,这样安装gtk时就会去搜索/usr/local/lib,同样可以找到需要的库
将/usr/local/lib加入到/etc/ld.so.conf也是必须的,这样以后安装东东到local下,就不会出现这样的问题了。
将自己可能存放库文件的路径都加入到/etc/ld.so.conf中是明智的选择 ^_^
添加方法也极其简单,将库文件的绝对路径直接写进去就OK了,一行一个。例如:
/usr/X11R6/lib
/usr/local/lib
/opt/lib

再来看看ldconfig是个什么东东吧 :

它是一个程序,通常它位于/sbin下,是root用户使用的东东。具体作用及用法可以man ldconfig查到
简单的说,它的作用就是将/etc/ld.so.conf列出的路径下的库文件 缓存到/etc/ld.so.cache 以供使用
因此当安装完一些库文件,(例如刚安装好glib),或者修改ld.so.conf增加新的库路径后,需要运行一下/sbin/ldconfig
使所有的库文件都被缓存到ld.so.cache中,如果没做,即使库文件明明就在/usr/lib下的,也是不会被使用的,结果
编译过程中抱错,缺少xxx库,去查看发现明明就在那放着,搞的想大骂computer蠢猪一个。 ^_^
我曾经编译KDE时就犯过这个错误,(它需要每编译好一个东东,都要运行一遍),所以

切记改动库文件后一定要运行一下ldconfig,在任何目录下运行都可以。


再来说说 PKG_CONFIG_PATH这个变量吧:

经常在论坛上看到有人问"为什么我已经安装了glib-2.4.x,但是编译gtk+-2.4.x 还是提示glib版本太低阿?
为什么我安装了glib-2.4.x,还是提示找不到阿?。。。。。。"都是这个变量搞的鬼。
先来看一个编译过程中出现的错误 (编译gtk+-2.4.13):

checking for pkg-config... /usr/bin/pkg-config
checking for glib-2.0 >= 2.4.0 atk >= 1.0.1 pango >= 1.4.0... Package glib-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glib-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glib-2.0' found

configure: error: Library requirements (glib-2.0 >= 2.4.0 atk >= 1.0.1 pango >= 1.4.0) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.
[root@NEWLFS gtk+-2.4.13]#
很明显,上面这段说明,没有找到glib-2.4.x,并且提示应该将glib-2.0.pc加入到PKG_CONFIG_PATH下。
究竟这个pkg-config PKG_CONFIG_PATH glib-2.0.pc 是做什么的呢? let me tell you ^_^
先说说它是哪冒出来的,当安装了pkgconfig-x.x.x这个包后,就多出了pkg-config,它就是需要PKG_CONFIG_PATH的东东
pkgconfig-x.x.x又是做什么的? 来看一段说明:

The pkgconfig package contains tools for passing the include path and/or library paths to build tools during the make file execution.

pkg-config is a function that returns meta information for the specified library.

The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix we use to install pkgconfig. You may add to PKG_CONFIG_PATH by exporting additional paths on your system where pkgconfig files are installed. Note that PKG_CONFIG_PATH is only needed when compiling packages, not during run-time.

我想看过这段说明后,你已经大概了解了它是做什么的吧。
其实pkg-config就是向configure程序提供系统信息的程序,比如软件的版本啦,库的版本啦,库的路径啦,等等
这些信息只是在编译其间使用。你可以 ls /usr/lib/pkgconfig 下,会看到许多的*.pc,用文本编辑器打开
会发现类似下面的信息:

prefix=/usr
exec_prefix=$
libdir=$/lib
includedir=$/include

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: GLib
Description: C Utility Library
Version: 2.4.7
Libs: -L$ -lglib-2.0
Cflags: -I$/glib-2.0 -I$/glib-2.0/include

明白了吧,configure就是靠这些信息判断你的软件版本是否符合要求。并且得到这些东东所在的位置,要不去哪里找呀。
不用我说你也知道为什么会出现上面那些问题了吧。

解决的办法很简单,设定正确的PKG_CONFIG_PATH,假如将glib-2.x.x装到了/usr/local/下,那么glib-2.0.pc就会在
/usr/local/lib/pkgconfig下,将这个路径添加到PKG_CONFIG_PATH下就可以啦。并且确保configure找到的是正确的
glib-2.0.pc,就是将其他的lib/pkgconfig目录glib-2.0.pc干掉就是啦。(如果有的话 ^-^)
设定好后可以加入到~/.bashrc中,例如:
PKG_CONFIG_PATH=/opt/kde-3.3.0/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/pkgconfig:
/usr/X11R6/lib/pkgconfig
[root@NEWLFS ~]#echo $PKG_CONFIG_PATH
/opt/kde-3.3.0/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/pkgconfig:/usr/X11R6/lib/pkgconfig

从上面可以看出,安装库文件时,指定安装到/usr,是很有好处的,无论是/etc/ld.so.conf还是PKG_CONFIG_PATH
默认都会去搜索/usr/lib的,可以省下许多麻烦,不过从源码包管理上来说,都装在/usr下
管理是个问题,不如装在/usr/local下方便管理
其实只要设置好ld.so.conf,PKG_CONFIG_PATH路径后,就OK啦 ^_^

附:ldconfig man(8)

Name
/sbin/ldconfig - configure dynamic linker run time bindings

Synopsis
/sbin/ldconfig [ -nNvXV ] [ -f conf ] [ -C cache ] [ -r root ] directory ...
/sbin/ldconfig -l [ -v ] library ...
/sbin/ldconfig -p

Description


ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.

ldconfig will attempt to deduce the type of ELF libs (ie. libc5 or libc6/glibc) based on what C libs, if any, the library was linked against. Therefore, when making dynamic libraries, it is wise to explicitly link against libc (use -lc).

Some existing libs do not contain enough information to allow the deduction of their type. Therefore, the /etc/ld.so.conf file format allows the specification of an expected type. This is only used for those ELF libs which we can not work out. The format is "dirname=TYPE", where TYPE can be libc4, libc5, or libc6. (This syntax also works on the command line.) Spaces are not allowed. Also see the -p option. ldconfig should normally be run by the superuser as it may require write permission on some root owned directories and files.

Options
-v
Verbose mode. Print current version number, the name of each directory as it is scanned, and any links that are created. Overrides quiet mode.

-n

Only process directories specified on the command line. Don't process the trusted directories (/lib and /usr/lib) nor those specified in /etc/ld.so.conf. Implies -N.

-N

Don't rebuild the cache. Unless -X is also specified, links are still updated.

-X

Don't update links. Unless -N is also specified, the cache is still rebuilt.

-f conf
Use conf instead of /etc/ld.so.conf.
-C cache
Use cache instead of /etc/ld.so.cache.
-r root
Change to and use root as the root directory.
-l
Library mode. Manually link individual libraries. Intended for use by experts only.

-p

Print the lists of directories and candidate libraries stored in the current cache.

Files
/lib/ld.so
run-time linker/loader

/etc/ld.so.conf

File containing a list of colon, space, tab, newline, or comma-separated directories in which to search for libraries.

/etc/ld.so.cache

File containing an ordered list of libraries found in the directories specified in /etc/ld.so.conf.

分享到:
评论

相关推荐

    \Linux下库的设置:ld.so.conf_文件与PKG_CONFIG_PATH变量

    Linux下库的设置:ld.so.conf_文件与PKG_CONFIG_PATH变量配置理解

    libgd相关资源文件

     2、加入动态库文件所在的目录:执行vi /etc/ld.so.conf,在"include ld.so.conf.d/*.conf"下方增加"/usr/local/lib"。  3、保存后,在命令行终端执行:/sbin/ldconfig -v;其作用是将文件/etc/ld.so.conf列出的...

    ubuntu网络重启后或主机重启后,_etc_resolv.conf恢复原样的解决办法 - 正风三才的博客 - CSDN博客1

    1.需要创建个件/etc/resolvconf/resolv.conf.d/tail 2.在该件中写需要的dns服务器,格式与/etc/resolv.conf相

    解决Cent0S 6.7直接在/etc/resolv.conf文件下修改DNS地址重启不生效问题

    主要介绍了解决Cent0S 6.7直接在/etc/resolv.conf文件下修改DNS地址重启不生效问题 ,需要的朋友可以参考下

    ubantu16下的oracle12.1 client安装文件

    sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf" sudo ldconfig export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH sudo mkdir -p ...

    dp18_ap6330整理完工20170209_1129.7z

    device/softwinner/tulip-d1/bluetooth/bt_vendor.conf:system/etc/bluetooth/bt_vendor.conf 5、2.4G/5.8G的WIFI双频段的支持: Z:\home\wwt\dp18_ap6330\android\device\softwinner\tulip-d1\overlay\...

    安装lamp报错信息及解决方法

    httpd: Syntax error on line 57 of /etc/httpd/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: xmlTextReaderSetup ...

    cuda报错 OSError: libcudart.so.10.0: cannot open shared object file: No such file

    有时候会碰到cuda报错,OSError: libcudart.so.10.0: cannot open shared object ...ldconfig 命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态

    openssl-1.1.1a.tar.gz

    文件:openssl-1.1.1a.tar.gz ...# echo "/usr/local/lib" >> /etc/ld.so.conf //新增动态链接库 # ldconfig //重新调用,或者重启系统 # openssl version -a //圆满了,看到版本号和路径 # reboot //重启

    nginx优化 使用Google的开源TCMalloc库

    # echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf # /sbin/ldconfig 3:重新编译nginx 不会安装的看这里 http://www.yunwei8.com/nginx124/ # cd /soft/nginx-1.2.4 # ./configure --user=...

    操作系统安全:ClamAV安装及部署.docx

    # cp /etc/freshclam.conf /etc/freshclam.conf.bak # sed -i -e "s/^Example/#Example/" /etc/freshclam.conf # cp /etc/clamd.conf /etc/clamd.conf.bak # sed -i -e "s/^Example/#Example/" /etc/clamd.conf # ...

    zabbix.conf

    /etc/httpd/conf.d/zabbix.conf ,Zabbix monitoring system php web frontend 配置时区等。

    ftp服务部署及使用,/etc/vsftpd/vsftpd.conf

    ftp服务部署及使用,/etc/vsftpd/vsftpd.conf

    zabbix安装配置文档

    ..../configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/...--enable-gd-native-ttf --enable-gd-jis-conv --with-jpeg-...

    nginx-lua环境配置

    2、安装Luajit2.0.2 make ...echo '/usr/local/lib' >> /etc/ld.so.conf.d/lua.conf ldconfig 问题: 需要把usr/local/lib中的liblua包映射到/lib目录下面。 ln -s /usr/local/lib/liblua* /lib

    kaleb_jacob_angelica

    echo "/usr/<java>//include > /etc/ld.so.conf.d/your.conf sudo ldconfig 例如在我的系统上它看起来像这样: 回声“/usr/lib/jvm/java-7-openjdk-i386/include”> /etc/ld.so.conf.d/kaleb.conf sudo ldconfig #...

    nginx_1.16.1-1_xenial_amd64.deb (ubuntu16.0.4)

    B、修改配置文件/etc/nginx/conf.d/default.conf 2.启动Nginx服务 sudo /etc/init.d/nginx start 3.优雅停止Nginx服务 sudo /etc/init.d/nginx quit 4.加载最新配置 sudo /etc/init.d/nginx reload 5.立即停止Nginx...

    Dockerfile 安装php7.1镜像

    --with-config-file-path=/usr/local/php/etc \ --with-gd \ --enable-pdo \ --with-openssl \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --enable-...

    rediSearch.so redisJson.so

    编译好的rediSearch.so redisJson.so redis安装包下创建module目录,放入redisearch.so rejson.so #redis中添加引用 vim /opt/redis6/bin/redis.conf loadmodule /opt/redis/module/redisearch.so loadmodule /...

Global site tag (gtag.js) - Google Analytics