zoukankan      html  css  js  c++  java
  • Linux: Set OR Change The Library Path

    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

  • 相关阅读:
    第10组 Beta冲刺(4/4)
    第10组 Beta冲刺(3/4)
    第10组 Beta冲刺(2/4)
    第10组 Beta冲刺(1/4)
    第10组 Alpha冲刺(4/4)
    租房这件事
    idea中的maven工程,有的项目名称显示粗体,有的显示中括号
    win10电脑版微信数字输入的间隔变大解决办法
    在实体类中添加了@ApiModel不起作用
    为数字字符串加上千分位符号
  • 原文地址:https://www.cnblogs.com/jjkv3/p/3822152.html
Copyright © 2011-2022 走看看