The following is the code where the API dlopen, dlsysm works different in Linux and Solaris,

File: dltrylib.c
****************
Code:
#include<stdio.h>
extern void printdltry();

void dltrylib_initialise()
{
printf("I am in library\n");
printdltry();
}
File:dltry.c
***********
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <dlfcn.h>
#include <fcntl.h>
void printdltry();

main()
{

void (*userfct_init)(); /* User initialize function returned by load()*/
char *libdir = NULL; /*Directory to search the .so*/
void *handle; /* Handle on the dynamic linked library*/
char pathso[100];
char userfct_name[256];

handle = dlopen( "/tmp/dltry/dltrylib.so", RTLD_NOW );

if ( NULL != handle )
{
memset( userfct_name, '\0', sizeof(userfct_name) );
(void)strcpy( userfct_name, "dltrylib_initialise");

userfct_init = (void (*)())dlsym( handle, userfct_name );

if ( NULL != userfct_init )
{
/* ... Load complete. Call the initialize function ...*/
(void)(*userfct_init)();
}
else
{
fprintf(stderr, ": %s\n", dlerror());
}

(void)dlclose( handle );
printf("Main: Library Loaded successfully loaded\n");

else
{
printf("Unable to load the library\n");
fprintf(stderr, ": %s\n", dlerror());

}

}

void printdltry()
{
printf("dlxxxx services work perfectly fine\n");
}
Compilation steps followed:
***************************
a) cc -g -c dltrylib.c
b) ld -G -o /tmp/dltry/dltrylib.so dltrylib.o
c) cc -g -c dltry.c
d) cc -o dltry dltry.o -ldl -lrt

From Solaris machine:
*********************
1. Above Compilation procedure,
2. Run,
>dltry
Lib: I am in shared library
dlxxxx services work perfectly fine
Main: Library loaded successfully loaded

From Linux machine:
*******************
1. Above Compilation procedure followed,
2. Run,
>dltry
Unable to load the library
: /tmp/dltry/dltrylib.so: undefined symbol: printdltry

3. Now, if the step d) in compilation is changed as
> cc -o dltry dltry.o /tmp/dltry/dltrylib.so -ldl -lrt
4. Now, run
>dltry
Lib: I am in shared library
dlxxxx services work perfectly fine
Main: Library loaded successfully loaded

Can somebody tell me why this shared library (dltrylib.so) needs to be linked in linux? or What is the alternative solution for this?
This means the dl routines in linux does not suport the direct access to the dynamic linking facilities as expected.



Any support on this line is highly appreciated.
Thanks for your understanding.