Linux: Set OR Change The Library Path

by NIX CRAFT on APRIL 9, 2010 · 3 COMMENTS· LAST UPDATED AUGUST 11, 2013

in GNU C / C++, LINUX, PROGRAMMING

I've compile and installed a library at /usr/local/lib/libapp2.so -> libapp2.so.1.4.3. How do I set the Library path under Linux operating systems?
You need to use ldconfig config file and ldconfig command which 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 such as /lib64 or /usr/lib64 (/lib or /usr/lib on 32 bit systems).

Tutorial details

Difficulty
Intermediate (rss)

Root privileges
Yes

Requirements
GNU gcc

Estimated completion time
10m

The /etc/ld.so.conf contains lib settings which can be used to add or delete paths. However, you need to simply drop your config file in /etc/ld.so.conf.d/ directory and it will be used by /sbin/ldconfig to configure dynamic linker run time bindings.

Add Your Path

Create a file called /etc/ld.so.conf.d/myapp.conf:
# vi /etc/ld.so.conf.d/myapp.conf
Add the following path:

/usr/local/lib

Save and close the file.

Activate Your Library Path

You must run the following command to activate path:
# ldconfig

Verify Your New Library Path

# ldconfig -v | less
OR
# ldconfig -v | grep /usr/local/lib
Sample outputs:

/usr/local/lib:
libGeoIP.so.1 -> libGeoIP.so.1.4.6
libGeoIPUpdate.so.0 -> libGeoIPUpdate.so.0.0.0
/usr/lib64/mysql:
libmysqlclient_r.so.15 -> libmysqlclient_r.so.15.0.0
libmysqlclient.so.15 -> libmysqlclient.so.15.0.0
/lib:
libutil.so.1 -> libutil-2.5.so

How Do I Delete The Library Path?

Simply, delete the file:
# rm /etc/ld.so.conf.d/myapp.conf
# ldconfig

How Do I Edit The Library Path?

Simply edit the file and reload the changes:
# vi /etc/ld.so.conf.d/myapp.conf
# ldconfig

How Do I Compile Program With Shared Libs And GNU GCC?

You can use the following gcc
$ gcc -Wl,-R/path/to/lib -I/path/to/include -L/path/to/lib -o myAppName mycode.c -llibapp2

Linux: Set OR Change The Library Path的更多相关文章

  1. Java加载dll或so库文件的路径 java.library.path

      1. Java的System.load 和 System.loadLibrary都可以用来加载库文件   2.例如你可以这样载入一个windows平台下JNI库文件: System.load(&q ...

  2. no ocijdbc11 in java.library.path linux

    no ocijdbc11 in java.library.path linux vi /etc/profile export ORACLE_HOME=/oracle/database/oracle/p ...

  3. java出现no XXX in java.library.path的解决办法及eclipse配置

    java一般使用两个path:classpath 和 java.library.path classpath是指向jar包的位置 java.library.path是非java类包的位置如(dll,s ...

  4. java.lang.UnsatisfiedLinkError: no XXX in java.library.path

    其中涉及的测试源码如下: For those who didn't install Javawith default settings, a systematic way for solving JN ...

  5. 不同系统与程序修改java.library.path的位置(转)

    原文地址:http://blog.csdn.net/quqibing001/article/details/51201768 Linux环境 系统变量LD_LIBRARY_PATH来添加Java.li ...

  6. no libsigar-amd64-linux.so in java.library.path 解决方法

    关于sigar的介绍可以参考这边博文 :https://www.cnblogs.com/luoruiyuan/p/5603771.html 在Linux上运行java程序时出现 no libsigar ...

  7. no xxx find in java.library.path

    JAVA系统运行时候load native lib时候会遇到下面错误,如 java.lang.UnsatisfiedLinkError: no JSTAF in java.library.path这可 ...

  8. 异常:没有找到本地方法库,java.lang.UnsatisfiedLinkError: no trsbean in java.library.path

    1.问题描述 迁移环境中遇到这个问题 : Fri Apr 20 15:22:31 CST 2018, Exception:500004___-500004,没有找到本地方法库,java.lang.Un ...

  9. The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path 问题解决记录

    1.问题 启动Tomcat之后,在浏览器输入IP后显示503,查看catalina.log发现报错: 2.问题定位:缺少 tomcat-native library 就是说 缺少Tomcat Nati ...

随机推荐

  1. 使用servers 启动项目时 ,一直处于启动中, 最后出现无法的问题。

    使用eclipse 中的servers 配置了一个server 来启动项目, 发现无法启动 排除法: 去掉项目配置,单独启动该server ,发现可以启动, 说明是项目出现问题 但是项目并没有报错, ...

  2. ubuntu 14.04 编译内核出现unable to locate package ncurses-devel 问题的解决

    http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c422461614 ...

  3. 360极速浏览器UA怪异以及如何用js判断360浏览器

    本文最后一次更新于7个月前,文章内容可能略有出入.若发现文章中有错误之处,可以留言评论告诉作者. 1.360极速浏览器UA因域名不同而异 今天在写一个判断浏览器.浏览器版本.操作系统.操作系统版本.浏 ...

  4. js-特效部分学习-拖拽效果

    一.客户区大小ClientWidth和ClientHeight <style> #box { width: 200px; height: 200px; background-color: ...

  5. ARP协议

    ARP协议就是一个获取对方MAC地址的协议,ARP协议它是一个网络层的协议,它的作用是通过ARP request报文来获得对方的MAC地址,ARP报文里面发送的内容大概是192.168.1.20你的M ...

  6. linux 中如何修改时间 date

    修改linux的时间可以使用date指令  修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009  修改时间: 将系统时间设定成上午10点18分0秒的命令如下 ...

  7. centos 安装PGSQL

    centos 安装PGSQLCentOS下yum安装PostgreSQL目录 1 Configure YUM repository2 Install PGDG RPM file3 Install Po ...

  8. 【Python自动化运维之路Day2】

    1. 常量命名规则 在Python中,会在变量命名上标明某变量是常量,通常采用全是大写的方式来标明,如: CONNECT= '127.0.0.1' PORT = ' 2.Python编译 python ...

  9. RegexKit: A Regular Expression Toolbox Based On NW.js(Node-Webkit) And Other Greate Open Source Projects.

    RegexKit RegexKit: A Regular Expression Toolbox Based On NW.js(Node-Webkit) And Other Greate Open So ...

  10. node-webkit教程(13)gpu支持信息查看

    node-webkit教程(13)gpu支持信息查看 文/玄魂 目录 node-webkit教程(13)gpu支持信息查看 前言 13.1操作步骤 (一)打开node-webkit,输入chrome: ...