您的位置:首页 > 运维架构 > Linux

linux操作之:可执行文件,库文件路径设置!

2008-12-19 13:06 357 查看
经常被人家问到这个问题,路径怎么设置阿?
我怎么离开了可执行文件的文件夹以后就没有办法使用可执行文件了阿?
我用export为什么总是不对阿?

问题很多,这里介绍一种很直接很简单的方法,其实操作很简单,熟悉linux的朋友们因该都知道,算是给不是很熟悉linux的使用的朋友的一点帮助吧

操作系统:opensuse 11.1 64位版本

1 设置可执行文件路径,我们直接修改系统文件来实现,很简单:
在终端里面执行:
BTazuo:/etc # cd /etc
BTazuo:/etc # vim profile
profile文件有点大,东西很多,找到PATH字样如图的地方:




for dir in /usr/X11/bin /

这行下面添加自己的可执行文件就是了。

2 设置库文件路径,依旧是修改系统文件如下:
BTazuo:~ # cd /etc
BTazuo:/etc # vim ld.so.conf

里面如图:




include /etc/ld.so.conf.d/*.conf

之前添加你的库文件也就是lib文件的路径就ok了。

重启就ok了,哈哈。
操作系统:Centos 58
可执行文件路径,依旧是在/etc/profile中:
1 # /etc/profile
  2
  3 # System wide environment and startup programs, for login setup
  4 # Functions and aliases go in /etc/bashrc
  5
  6 pathmunge () {
  7     if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
  8        if [ "$2" = "after" ] ; then
  9           PATH=$PATH:$1
 10        else
 11           PATH=$1:$PATH
 12        fi
 13     fi
 14 }
 15
 16 # ksh workaround
 17 if [ -z "$EUID" -a -x /usr/bin/id ]; then
 18     EUID=`id -u`
 19     UID=`id -ru`
 20 fi
 21
 22 # Path manipulation
 23 if [ "$EUID" = "0" ]; then
 24     pathmunge /sbin
 25     pathmunge /usr/sbin
 26     pathmunge /usr/local/sbin
 27 fi
# Path manipulation之后then里面添加你想要的可执行文件路径,比如/usr/local/share/xxx/bin即可
系统库路径,和上面一致:
[root@localhost etc]# ll ld*
-rw-r--r-- 1 root root   9028 Feb 23  2012 ldap.conf
-rw-r--r-- 1 root root 115468 Dec  9 15:07 ld.so.cache
-rw-r--r-- 1 root root     28 Oct  8  2006 ld.so.conf

ld.so.conf.d:
total 32
-r--r--r-- 1 root root 324 Dec  5 10:07 kernelcap-2.6.18-308.24.1.el5.conf
-r--r--r-- 1 root root 324 Feb 22  2012 kernelcap-2.6.18-308.el5.conf
-rw-r--r-- 1 root root  15 Feb 14  2012 mysql-i386.conf
-rw-r--r-- 1 root root  17 May 10  2012 openais-athlon.conf
-rw-r--r-- 1 root root  20 Feb 24  2012 qt-i386.conf
-rw-r--r-- 1 root root 276 Dec  9 03:59 vmware-tools-libraries.conf
-rw-r--r-- 1 root root  21 Nov 21 09:41 xulrunner-32.conf
[root@localhost etc]#
[root@localhost etc]# cd ld.so.conf.d/
[root@localhost ld.so.conf.d]# ll
total 32
-r--r--r-- 1 root root 324 Dec  5 10:07 kernelcap-2.6.18-308.24.1.el5.conf
-r--r--r-- 1 root root 324 Feb 22  2012 kernelcap-2.6.18-308.el5.conf
-rw-r--r-- 1 root root  15 Feb 14  2012 mysql-i386.conf
-rw-r--r-- 1 root root  17 May 10  2012 openais-athlon.conf
-rw-r--r-- 1 root root  20 Feb 24  2012 qt-i386.conf
-rw-r--r-- 1 root root 276 Dec  9 03:59 vmware-tools-libraries.conf
-rw-r--r-- 1 root root  21 Nov 21 09:41 xulrunner-32.conf
[root@localhost ld.so.conf.d]# cat mysql-i386.conf
/usr/lib/mysql
要添加库文件路径只需要在ld.so.conf.d:里面添加一个conf文件指定路径,比如上面的mysql-i386.conf,就指明了路径。之所以可以如此是因为:
在文件ld.so.conf里面只有一句:
1 include ld.so.conf.d/*.con

上面是两种简单的方法,属于修改系统设置了,最后说一下lib的搜索范围:
1.编译目标代码时指定的动态库搜索路径,比如gcc的时候-L指定lib路径,-l指定库文件名(不带.so后缀);
2.环境变量LD_LIBRARY_PATH指定的动态库搜索路径(静态库路径是LIBRARY_PATH);
3.配置文件/etc/ld.so.conf中指定的动态库搜索路径;
4.默认的动态库搜索路径/lib;
5.默认的动态库搜索路径/usr/lib。

版权所有,转载请注明!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐