Originally Posted by Nilesh Tekale
Thanks for your reply.
but as per the man page RTLD_LAZY Only resolve symbols as the code that references them is executed and I've never called fun() or fun2() to execute.In fun5.c I've only defined those function and never called.
You did call the function fun5 in fun5.so. And that required it to be loaded - and in turn that required fun2.so.
Had you NOT called fun5, then neither library would have been loaded.
Both get loaded because it is an explicit dependency between fun5.so and fun2.so. If the application is going to call fun5, then both libraries MUST be loaded. dlopen has no way to know ahead of time if fun2 is/is not going to be needed - and doesn't have any way to determine that.
Now if fun5 used dlopen to load the fun2.so with a lazy open then it would only be loaded IF something fun5 did called a function in fun2.so.