-   Linux - General (
-   -   Problem in using both load time linking and runtime linking (

durgaprasad_j 08-01-2006 03:49 AM

Problem in using both load time linking and runtime linking
Hi All,

I have a small shared library file named

I have written a small program to load this library in runtime
using dlopen, dlclose etc. In that program I open that library using
dlopen once and close that library twice using dlclose.

So, when I compile the program normally, gcc test.c -ldl, it is
working fine. It is printing dlerror message when it is executing
dlclose second time.

But, when I compile the program with load time linking also, gcc
test.c -L<somedir> -ldl -ltest1, 2nd dlclose is also working fine in
some systems with out any error message from dlerror function. I have
tested this program in 2 linux systems. In RHEL AS Release 4, KERNEL:
2.6.9-34.0.2.EL , it is printing dlerror after 2nd dlclose [This is
what I have expected]. But in Suse 8.1, KERNEL: 2.4.21-138-default,
even the 2nd dlclose result is SUCCESS.

I dont know how system handles if load time linking and runtime
linking is done on the same libraries. If you know it, please explain

If anyone of you have faced this kind of problem earlier and solved
them, please help me.

This is the C Program that I have written.
int main(int argc,char* argv)
void* handle_test1=dlopen("",RTLD_NOW|RTLD_GLOBAL);
printf("Test1 Error\n");
printf("test1 open is succesful\n");

int close_val=dlclose(handle_test1);
printf("test1 close#1 is %d , %s \n",close_val,dlerror());
printf("test1 close#2 is %d , %s \n",close_val,dlerror());

Thank you
Durga Prasad

All times are GMT -5. The time now is 05:46 AM.