I've been searching a way to make a shared library (let's name the library libbar.so
) delay loaded on Linux and it should hopefully be realized with a help from only a linker, not modifying anything on the source code written in C++; I mean I don't want to invoke dlopen()
nor dlsym()
in the source code of the parent library (let's name it libfoo.so
) to invoke a function of libbar.so
because they make the source code messy and the maintenance process difficult. (In short, I'm expecting to go on the similar way to Visual Studio's /DELAYLOAD
option even on Linux)
Anyway, I've found some uncertain information pieces related to my question on the internet so far, so it would be very nice to have the answers from you all for the following questions to make the information clear.
- Does GNU ld support any delay loading mechanism on Linux?
- If it doesn't, how about Clang?
- Is the
dlopen()
family the only way to make a shared library delay loaded on Linux?
I tested to pass -zlazy
flag to GCC (g++) with a path to the library, it seemed to accept the flag but the behavior did not look making libbar.so
delay loaded (Not having libbar.so
, I was expecting to have an exception at the first call of libbar.so
, but the exception actually raised before entering to libfoo.so
). On the other hand, Clang (clang++
) left a warning that it ignored the option flag.
Best regards,
See Question&Answers more detail:os