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. caffe 安装在win 7 vs2015 无gpu的安装方式-是无法安装 的

    网上多数是vs2012或者vs2013上安装方式,带NA-显卡的需要安装CUDA7.5,安装cuDNN4,cuDNN. 一 :下载caffe源码(microsoft版) 下载地址:https://gi ...

  2. [转载]PHP 5.6 on CentOS/RHEL 7.0 and 6.6 via Yum

    https://webtatic.com/packages/php56/ PHP 5.6.5 has been released on PHP.net on 22nd January 2014, an ...

  3. VB6.0和VB.Net的函数等对照表

    VB6.0和VB.Net的对照表 VB6.0 VB.NET AddItem Object名.AddItem Object名.Items.Add ListBox1.Items.Add ComboBox1 ...

  4. c++ 操作注册表

    1.       注册表简介 注册表是为Windows NT和Windows95中所有32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (Win ...

  5. jsp_数据库的连接

    一.添加数据库以及表 在这里我们使用的是mysql数据库 二.配置数据库的驱动程序 将mysql的驱动程序复制到Tomcat目录下的lib目录中 注:在Tomcat中如果配置了新的jar包,则配置完成 ...

  6. 【03_136】Single Number

    感谢:http://www.cnblogs.com/changchengxiao/p/3413294.html Single Number Total Accepted: 103007 Total S ...

  7. .NET跨平台:在mac命令行下用vim手写ASP.NET 5 MVC程序

    昨天在 Mac 上手写了一个最简单的 ASP.NET 5 程序,直接在 Startup.cs 中通过 Response.WriteAsync() 输出响应内容,详见 .NET跨平台:在Mac上跟着错误 ...

  8. 如何在Global.asax中判断是否是ajax请求

    今天在一个应用场景中需要在Global.asax中判断一个请求是否是ajax请求,而在ASP.NET MVC中已经提供了一个现成的扩展方法IsAjaxRequest: namespace System ...

  9. missing locales

    原文地址:http://codewut.de/content/missing-locales-under-debian This drives me crazy! Every time I deboo ...

  10. Chrome浏览器在Windows8/8.1下显示模糊的解决办法

    刚刚换了一台新电脑,安装完Windows 8.1,屏幕分辨率被自动设置为1920 X 1080,打开Chrome浏览器却发现内容显示非常模糊,不论如何改变Chrome的设置均没有效果,开启或关闭Chr ...