Thread: specifying shared library path to linker during compile time

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    1

    specifying shared library path to linker during compile time

    I would like to compile a binary that doesnot depend on LD_LIBRARY_PATH as this binary will be setuid to owner and used by other users and since setuid doesnot support LD_LIBRARY_PATH making it independent of LD_LIBRARY_PATH would be great.
    But I am not able to specify the path of the shared libraries to the linker at compile time. I am using gcc compiler 4.1.2 and on Linux OS Red Hat 5.8. I am using the following compile command where /aaa/bbb/lib is the path of the shared library that is used by the binary waitdb.ORACLE called within the binary simple:
    gcc simple.c -Wl,-rpath=/aaa/bbb/lib -o simple
    simple.c has nothing but an execvp call to another binary 'waitdb.ORACLE' which uses libuidata.so that is located in /aaa/bbb/lib directory
    Contents of simple.c are as follows:

    insert
    Code:
    #include <stdio.h>
    int main(int argc, char* argv[])
    {
    char* args[3];
    args[0]="/aaa/bbb/bin/waitdb.ORACLE";
    args[1]=NULL;
    printf ("before executing execvp\n");
    execvp (args[0],args);
    printf ("after executing execvp\n");
    }
    But when I run the executable 'simple' I get the following error
    [acdev2@hostname tmp]$ ./simple
    before executing execvp
    /aaa/bbb/bin/waitdb.ORACLE: error while loading shared libraries: libuidata.so: cannot open shared object file: No such file or directory

    On the other hand if I run at the commandline, the export LD_LIBRARY_PATH command before calling the binary it works FINE.
    [acdev2@hostname tmp]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/aaa/bbb/lib
    [acdev2@hostname1 tmp]$ ./simple
    before executing execvp
    +++INFO+++ 20140103_13:54:32 @(#)waitdb[6.2/$Revision: 5538 $]: RDBMS DNYASC01 is accepting connections

    Please advise how I can specify the /aaa/bbb/lib path to the linker at compile time of binary 'simple' so that when 'simple' binary tries to execvp 'waitdb.ORACLE' binary within it the linker knows where to find the libuidata.so shared library file that waitdb.ORACLE uses without using the LD_LIBRARY_PATH variable ?



    thanks

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    This is a Linux-specific question, please pick the right forum next time.

    Per your description, simple doesn't use libuidata.so, so putting it in the rpath for simple is pointless. execvp starts a whole new binary, waitdb.ORACLE, which uses libuidata.so, and needs libuidata.so in it's rpath. Set that option when building waitdb.ORACLE.

    If that isn't possible, but you have admin priveliges, consider installing the library in a standard location (or add the custom location to your /etc/ld.so.conf) and running ldconfig. Then whatever needs it, can find it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting path to shared object
    By dev.fb0 in forum Linux Programming
    Replies: 5
    Last Post: 04-07-2011, 04:48 PM
  2. problem in changing shared library path in linux
    By remyasj in forum Linux Programming
    Replies: 3
    Last Post: 08-06-2009, 08:31 AM
  3. shared library for QNX
    By ReeV in forum C Programming
    Replies: 3
    Last Post: 05-06-2009, 10:58 AM
  4. Replies: 3
    Last Post: 11-07-2006, 06:41 AM
  5. Replies: 1
    Last Post: 06-24-2005, 09:45 AM