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:
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:
But when I run the executable 'simple' I get the following error
On the other hand if I run at the commandline, the export LD_LIBRARY_PATH command before calling the binary it works FINE.
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
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)
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)
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)
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)
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)
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)
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)
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
LEARN ABOUT MOJAVE
uselib
USELIB(2) Linux Programmer's Manual USELIB(2)NAME
uselib - load shared library
SYNOPSIS
#include <unistd.h>
int uselib(const char *library);
Note: No declaration of this system call is provided in glibc headers; see NOTES.
DESCRIPTION
The system call uselib() serves to load a shared library to be used by the calling process. It is given a pathname. The address where to
load is found in the library itself. The library can have any recognized binary format.
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
ERRORS
In addition to all of the error codes returned by open(2) and mmap(2), the following may also be returned:
EACCES The library specified by library does not have read or execute permission, or the caller does not have search permission for one of
the directories in the path prefix. (See also path_resolution(7).)
ENFILE The system-wide limit on the total number of open files has been reached.
ENOEXEC
The file specified by library is not an executable of a known type; for example, it does not have the correct magic numbers.
CONFORMING TO
uselib() is Linux-specific, and should not be used in programs intended to be portable.
NOTES
This obsolete system call is not supported by glibc. No declaration is provided in glibc headers, but, through a quirk of history, glibc
versions before 2.23 did export an ABI for this system call. Therefore, in order to employ this system call, it was sufficient to manually
declare the interface in your code; alternatively, you could invoke the system call using syscall(2).
In ancient libc versions, uselib() was used to load the shared libraries with names found in an array of names in the binary.
Since libc 4.3.2, startup code tries to prefix these names with "/usr/lib", "/lib" and "" before giving up. In libc 4.3.4 and later these
names are looked for in the directories found in LD_LIBRARY_PATH, and if not found there, prefixes "/usr/lib", "/lib" and "/" are tried.
From libc 4.4.4 on only the library "/lib/ld.so" is loaded, so that this dynamic library can load the remaining libraries needed (again
using this call). This is also the state of affairs in libc5.
glibc2 does not use this call.
Since Linux 3.15, this system call is available only when the kernel is configured with the CONFIG_USELIB option.
SEE ALSO ar(1), gcc(1), ld(1), ldd(1), mmap(2), open(2), dlopen(3), capabilities(7), ld.so(8)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2017-09-15 USELIB(2)