Setting the path to find shared libraries files during runtime

This is a discussion on Setting the path to find shared libraries files during runtime within the Linux Programming forums, part of the Platform Specific Boards category; Hi all, I am trying to use shared libraries in Linux. I use dlopen to load a .so file, and ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    3

    Setting the path to find shared libraries files during runtime

    Hi all,

    I am trying to use shared libraries in Linux. I use dlopen to load a .so file, and it worked if I set LD_LIBRARY_PATH before running my program. However, I want to set the LD_LIBRARY_PATH using setenv during runtime, instead of setting it before running the probram. I use setenv to set the LD_LIBRARY_PATH, but that does not work, and dlopen returns an error that it cannot find the libXXXX.so file. Could anyone give me some hints to set the path to find shared library files during runtime?

    Thanks,
    Alan

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    Some ways to dlopen to work:
    1. an existing LD_LIBRARY_PATH that points to directories that contain your library
    or
    2. a link in the default library path (usually /usr/lib) that points to your library file
    or
    3. an explicit path or directory hard-coded into your source as part of the library name

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    Thanks for your reply. I have tried your solutions, but I am afraid that they cannot change the path to the shared library files during runtime. I am trying to get a path from the user, and load the shared libary file from that path, but using setenv to set the LD_LIBRARY_PATH during runtime does not work. The LD_LIBRARY_PATH in environment is changed, but dlopen does not use the new LD_LIBRARY_PATH. Is it possible to change the LD_LIBRARY_PATH when the program is running?

  4. #4
    .
    Join Date
    Nov 2003
    Posts
    307
    LD_PRELOAD creates library interposers - by default dlopen searches whatever is in the env variable LD_PRELOAD before it does anything else. LD_LIBRARY_PATH.

    man ld explains what LD_PRELOAD does. It may suit your needs. You are supposed to change those variables BEFORE program execution. Here is am example of why:
    http://sources.redhat.com/ml/libc-al.../msg00190.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. shared libraries
    By kris.c in forum Linux Programming
    Replies: 5
    Last Post: 12-25-2006, 07:08 PM
  3. Setting path environment variable
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 09-01-2006, 03:03 PM
  4. Setting DACL for Files and Folders
    By IfYouSaySo in forum Windows Programming
    Replies: 6
    Last Post: 01-07-2006, 12:27 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21