URGENT URGENT dlopen() help needed... 
Author Message
 URGENT URGENT dlopen() help needed...

    I have a very simple command-line that I use for this. This seems to
work the same for Sun's Workshop 4.2 C compiler as it does for the GNU C
compiler. Both are on my Sparc Solaris 2.51 workstation. To compile the
modules for you library:

cc -o object.o -c -KPIC -I<include path> source.c

    To link the objects into the shared object library:

ld -G -L<path to other libs to link in, if any> -o<output file name.so>
<.o object modules>

Then, when you compile/link your program with the .so file from above:

cc -o <executable name> -I<path to header files> -L<path to .so
libraries> -ldl <C source code>

    The important part above is to link in libdl.so with the -ldl
option. This links in the dynamic linking facilities which allows you to
use dlopen, etc. In fact, I followed the example from the dlsym(3X) man

void *handle;
int  *iptr, (*fptr)(int);

/* open the needed object */
handle = dlopen("/usr/home/me/libfoo.so.1", RTLD_LAZY);

/* find the address of function and data objects */
fptr = (int (*)(int))dlsym(handle, "my_function");
iptr = (int *)dlsym(handle, "my_object");

/* invoke function, passing value of integer as a parameter */

    The only thing I'm not sure about is if the object modules which are
linked in to the .so library have to be compiled to have position
independent code (-KPIC) or not. I am using an existing .a archive which
I converted into a .so library and am trying to call functions from it
with the above method. The dlopen() and dlsym() work OK, but the call to
the module hangs. Does anyone know if the modules in a .so library have
to be compiled to be position independent before they can be used via
dlopen(), dlsym(), etc?



> Hi,

> We are using Solaris 2.5. We have 3 to 4 shared libraries. In our
> application we are trying to open them
> using the dlopen() command. We used the

> ld -G ......

> compile options to create the shared library. But then the dlopen()
> fails.

> Can someone help us out here with the right --

> - Compile and link options to create a shared library....
> - using the dlopen() to open the created shared library.

> We are in a crunch time right now.
> Any input or help is appreciated. Email back at

> Regards

> Uday Pai

Fri, 01 Dec 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. URGENT URGENT PLEASE HELP ME ActiveX multiples classes

2. Urgent Help Needed-Calling the help file.

3. Urgent Need help

4. Need Urgent Help::::: Printer

5. Urgent Help needed!

6. need urgent help for string processing

7. Help needed with process class......kind of urgent

8. Directory Services URGENT NEEDED HELP

9. Socket programming urgent help needed

10. Need urgent help with this (fork, dup, pipes)

11. Urgent help needed!

12. Urgent Help needed


Powered by phpBB® Forum Software