Sponsored Content
Top Forums Programming Specifying dynamic library path to linker at compile time Post 302882013 by waavman on Friday 3rd of January 2014 02:11:33 PM
Old 01-03-2014
Specifying dynamic library path to linker at 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:

Code:
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:

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

Code:
[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.

Code:
[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 another c binary '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

Last edited by bartus11; 01-03-2014 at 03:32 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Programming

how to auto load a dynamic library

hi, every body. i have in trouble that how to load a dynamic library by hand. for example, i know how to generate a dynamic library and how to link a dynamic library in makefile. generate a dynamic library: add -dy -G behind cc link a dynamic library in makefile: add -dy -Bdynamic behind cc... (0 Replies)
Discussion started by: subrain
0 Replies

2. Programming

How compile a library on solaris(like dll in windows)

Hi all, how do i compile a c program into a library on solaris Thanks in advance Zing (3 Replies)
Discussion started by: zing
3 Replies

3. Programming

loading a dynamic library in linux

is there a way to load a dynamic library in linux? I know tht in AIX u can do it using the loadAndInit() function. Please guide me (2 Replies)
Discussion started by: jacques83
2 Replies

4. Programming

overriding the dynamic library

Hi, I wonder how can we override the dynamic library loaded by ld on start up.(dynamic linked application). so that linker uses the new library to find symbols. Is it possible to do. Cheers. (4 Replies)
Discussion started by: Raom
4 Replies

5. HP-UX

dynamic linker error

Hi All Could anyone help in giving a little background to the following runtime error. /usr/lib/pa20_64/dld.sl: Mmap failed due to errno: 13. Seen when executing a 64-bit ELF executable. Thanks Ed (3 Replies)
Discussion started by: C3000
3 Replies

6. Programming

Dynamic library load with dlopen

Hi, I created two library libsum.so and libproduct.so. In the libproduct.so is defined function "product" that use function "sum" defined in libsum.so. So libproduct depends on libsum. In main function I called product function by a dlopen request. Unfortunaly, when I execute program I have an... (5 Replies)
Discussion started by: shade82
5 Replies

7. SCO

SCO openserver Dynamic linker corruption

Hi every body I have a problem like that "Dynamic linker error" message. I can't load many of programs in sco unix openserver 5.0.6. I guess this problem appear after my last effort to install "SCO Development System" package. How can I fix this problem? would you please help me ? (1 Reply)
Discussion started by: javad1_maroofi
1 Replies

8. Programming

C Library reference error using sqrt() - will not compile.

This so basic that it should work.... Any ideas would be appreciared. Using a number directly in the sqrt allows it to compile. primrose > cat a.c #include <stdio.h> #include <math.h> int main(void) { double abcd=9; printf("%f\n",sqrt(abcd)); } primrose > gcc a.c Undefined first... (2 Replies)
Discussion started by: plastichead
2 Replies

9. Programming

problem in dynamic library*.so

hello I apologize if my question bothers you I work on a code developed in C + + which worked well on mac os, this code will help create libraries *.so from *.cc and *.h I used this as flags:CXXFLAGS = -g -O2 -fPIC -Wall -ldl -D_GNU_SOURCE ,CXX := g++ and $(CXX)-shared -o $(LIBNAME) $(CLIBLIB)... (0 Replies)
Discussion started by: pheapc
0 Replies

10. Programming

Gcc linker search path order

I have a build where I wish to link against and load a specific version of a library and a different version of the same library is installed on the system. I'm using a -L option to point to the version that I wish to link against but gcc still seems to choose the installed version. Is there a way... (4 Replies)
Discussion started by: Richard Johnson
4 Replies
LD.SO(8)						     Linux Programmer's Manual							  LD.SO(8)

NAME
ld.so, ld-linux.so* - dynamic linker/loader SYNOPSIS
The dynamic linker can be run either indirectly by running some dynamically linked program or library (in which case no command-line options to the dynamic linker can be passed and, in the ELF case, the dynamic linker which is stored in the .interp section of the program is executed) or directly by running: /lib/ld-linux.so.* [OPTIONS] [PROGRAM [ARGUMENTS]] DESCRIPTION
The programs ld.so and ld-linux.so* find and load the shared libraries needed by a program, prepare the program to run, and then run it. Linux binaries require dynamic linking (linking at run time) unless the -static option was given to ld(1) during compilation. The program ld.so handles a.out binaries, a format used long ago; ld-linux.so* handles ELF (/lib/ld-linux.so.1 for libc5, /lib/ld- linux.so.2 for glibc2), which everybody has been using for years now. Otherwise both have the same behavior, and use the same support files and programs ldd(1), ldconfig(8) and /etc/ld.so.conf. The shared libraries needed by the program are searched for in the following order: o (ELF only) Using the directories specified in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated. o Using the environment variable LD_LIBRARY_PATH. Except if the executable is a set-user-ID/set-group-ID binary, in which case it is ignored. o (ELF only) Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present. o From the cache file /etc/ld.so.cache which contains a compiled list of candidate libraries previously found in the augmented library path. If, however, the binary was linked with the -z nodeflib linker option, libraries in the default library paths are skipped. o In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped. $ORIGIN and rpath ld.so understands the string $ORIGIN (or equivalently ${ORIGIN}) in an rpath specification (DT_RPATH or DT_RUNPATH) to mean the directory containing the application executable. Thus, an application located in somedir/app could be compiled with gcc -Wl,-rpath,'$ORIGIN/../lib' so that it finds an associated shared library in somedir/lib no matter where somedir is located in the directory hierarchy. This facili- tates the creation of "turn-key" applications that do not need to be installed into special directories, but can instead be unpacked into any directory and still find their own shared libraries. OPTIONS
--list List all dependencies and how they are resolved. --verify Verify that program is dynamically linked and this dynamic linker can handle it. --library-path PATH Override LD_LIBRARY_PATH environment variable setting (see below). --inhibit-rpath LIST Ignore RPATH and RUNPATH information in object names in LIST. This option is ignored if ld.so is set-user-ID or set-group-ID. ENVIRONMENT
There are four important environment variables. LD_BIND_NOW (libc5; glibc since 2.1.1) If set to a nonempty string, causes the dynamic linker to resolve all symbols at program startup instead of deferring function call resolution to the point when they are first referenced. This is useful when using a debugger. LD_LIBRARY_PATH A colon-separated list of directories in which to search for ELF libraries at execution-time. Similar to the PATH environment vari- able. LD_PRELOAD A whitespace-separated list of additional, user-specified, ELF shared libraries to be loaded before all others. This can be used to selectively override functions in other shared libraries. For set-user-ID/set-group-ID ELF binaries, only libraries in the standard search directories that are also set-user-ID will be loaded. LD_TRACE_LOADED_OBJECTS (ELF only) If set to a nonempty string, causes the program to list its dynamic library dependencies, as if run by ldd(1), instead of running normally. Then there are lots of more or less obscure variables, many obsolete or only for internal use. LD_AOUT_LIBRARY_PATH (libc5) Version of LD_LIBRARY_PATH for a.out binaries only. Old versions of ld-linux.so.1 also supported LD_ELF_LIBRARY_PATH. LD_AOUT_PRELOAD (libc5) Version of LD_PRELOAD for a.out binaries only. Old versions of ld-linux.so.1 also supported LD_ELF_PRELOAD. LD_AUDIT (glibc since 2.4) A colon-separated list of user-specified, ELF shared objects to be loaded before all others in a separate linker namespace (i.e., one that does not intrude upon the normal symbol bindings that would occur in the process). These libraries can be used to audit the operation of the dynamic linker. LD_AUDIT is ignored for set-user-ID/set-group-ID binaries. The dynamic linker will notify the audit libraries at so-called auditing checkpoints--for example, loading a new library, resolving a symbol, or calling a symbol from another shared object--by calling an appropriate function within the audit library. For details, see rtld-audit(7). The auditing interface is largely compatible with that provided on Solaris, as described in its Linker and Libraries Guide, in the chapter Runtime Linker Auditing Interface. LD_BIND_NOT (glibc since 2.1.95) Do not update the GOT (global offset table) and PLT (procedure linkage table) after resolving a symbol. LD_DEBUG (glibc since 2.1) Output verbose debugging information about the dynamic linker. If set to all prints all debugging information it has, if set to help prints a help message about which categories can be specified in this environment variable. Since glibc 2.3.4, LD_DEBUG is ignored for set-user-ID/set-group-ID binaries. LD_DEBUG_OUTPUT (glibc since 2.1) File where LD_DEBUG output should be fed into, default is standard output. LD_DEBUG_OUTPUT is ignored for set- user-ID/set-group-ID binaries. LD_DYNAMIC_WEAK (glibc since 2.1.91) Allow weak symbols to be overridden (reverting to old glibc behavior). For security reasons, since glibc 2.3.4, LD_DYNAMIC_WEAK is ignored for set-user-ID/set-group-ID binaries. LD_HWCAP_MASK (glibc since 2.1) Mask for hardware capabilities. LD_KEEPDIR (a.out only)(libc5) Don't ignore the directory in the names of a.out libraries to be loaded. Use of this option is strongly dis- couraged. LD_NOWARN (a.out only)(libc5) Suppress warnings about a.out libraries with incompatible minor version numbers. LD_ORIGIN_PATH (glibc since 2.1) Path where the binary is found (for non-set-user-ID programs). For security reasons, since glibc 2.4, LD_ORI- GIN_PATH is ignored for set-user-ID/set-group-ID binaries. LD_POINTER_GUARD (glibc since 2.4) Set to 0 to disable pointer guarding. Any other value enables pointer guarding, which is also the default. Pointer guarding is a security mechanism whereby some pointers to code stored in writable program memory (return addresses saved by setjmp(3) or function pointers used by various glibc internals) are mangled semi-randomly to make it more difficult for an attacker to hijack the pointers for use in the event of a buffer overrun or stack-smashing attack. LD_PROFILE (glibc since 2.1) Shared object to be profiled, specified either as a pathname or a soname. Profiling output is written to the file whose name is: "$LD_PROFILE_OUTPUT/$LD_PROFILE.profile". LD_PROFILE_OUTPUT (glibc since 2.1) Directory where LD_PROFILE output should be written. If this variable is not defined, or is defined as an empty string, then the default is /var/tmp. LD_PROFILE_OUTPUT is ignored for set-user-ID and set-group-ID programs, which always use /var/profile. LD_SHOW_AUXV (glibc since 2.1) Show auxiliary array passed up from the kernel. For security reasons, since glibc 2.3.5, LD_SHOW_AUXV is ignored for set-user-ID/set-group-ID binaries. LD_USE_LOAD_BIAS By default (i.e., if this variable is not defined) executables and prelinked shared objects will honor base addresses of their dependent libraries and (nonprelinked) position-independent executables (PIEs) and other shared objects will not honor them. If LD_USE_LOAD_BIAS is defined wit the value, both executables and PIEs will honor the base addresses. If LD_USE_LOAD_BIAS is defined with the value 0, neither executables nor PIEs will honor the base addresses. This variable is ignored by set-user-ID and set- group-ID programs. LD_VERBOSE (glibc since 2.1) If set to a nonempty string, output symbol versioning information about the program if querying information about the program (i.e., either LD_TRACE_LOADED_OBJECTS has been set, or --list or --verify options have been given to the dynamic linker). LD_WARN (ELF only)(glibc since 2.1.3) If set to a nonempty string, warn about unresolved symbols. LDD_ARGV0 (libc5) argv[0] to be used by ldd(1) when none is present. FILES
/lib/ld.so a.out dynamic linker/loader /lib/ld-linux.so.{1,2} ELF dynamic linker/loader /etc/ld.so.cache File containing a compiled list of directories in which to search for libraries and an ordered list of candidate libraries. /etc/ld.so.preload File containing a whitespace separated list of ELF shared libraries to be loaded before the program. lib*.so* shared libraries NOTES
The ld.so functionality is available for executables compiled using libc version 4.4.3 or greater. ELF functionality is available since Linux 1.1.52 and libc5. SEE ALSO
ldd(1), rtld-audit(7), ldconfig(8) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2009-01-12 LD.SO(8)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy