Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resolving names from shared libraries instead of the executable

Status
Not open for further replies.

pallabdasgupta

Programmer
Mar 13, 2003
1
US
I have an executable EXE which loads two shared libraries SL1 and SL2. SL1 refers to a symbol SYM which is in both SL2 and the executable EXE.
The EXE is built with the -E flag.

I want the call to SYM from SL1 to resolve to the one in SL2, and not the one in EXE.

On Solaris, I do this by using the -Bdirect switch of ld while building SL2 and using -lSL1

I could not find an equivalent for HP. Is there one ?
 
this example run on hp.
Mybe this one can help u.

#include <dlfcn.h>
#include <errno.h>
#include <stdio.h>

void main (void)
{
void *(*fn)();
void *lib;
char *e;
int c;

if ((lib = dlopen (&quot;./lib.so&quot;, RTLD_NOW)) == NULL)
{
e = dlerror();
printf (&quot;%s\n&quot;, e);
exit (3);
}
if ((fn = dlsym (lib, &quot;myprint&quot;)) == NULL)
{
perror (dlerror());
exit (4);
}
(*fn)(&quot;Hello World&quot;);
(*fn)(&quot;Press Enter&quot;);
c = getchar();
if (dlclose (lib) != 0) {
perror (&quot;Can't unload lib&quot;);
exit (3);
}
}

the makeFile:
all: main lib.sl

main: main.c lib.sl Makefile
cc -Ae -o main main.c /usr/lib/libdld.2
#./main
lib.sl: lib.c Makefile lib1.c
cc -Ae -n -b -o lib.sl lib.c
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top