LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Problem in using both load time linking and runtime linking (https://www.linuxquestions.org/questions/linux-general-1/problem-in-using-both-load-time-linking-and-runtime-linking-469631/)

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 libtest1.so

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
me.

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.
*/
#include<stdio.h>
#include<dlfcn.h>
int main(int argc,char* argv)
{
void* handle_test1=dlopen("libtest1.so",RTLD_NOW|RTLD_GLOBAL);
if(!handle_test1)
printf("Test1 Error\n");
else
printf("test1 open is succesful\n");

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

Thank you
Durga Prasad


All times are GMT -5. The time now is 07:22 AM.