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