Delay-Load equivalent in unix based systems Delay-Load equivalent in unix based systems unix unix

Delay-Load equivalent in unix based systems


See the reference on your system for dlopen(). You can manually open libraries and resolve external symbols at runtime rather than at link time.

Dug out an example:

int main(int argc, char **argv) {                     void *handle=NULL;                                     double (*myfunc)(double);                         char *err=NULL;                                      handle = dlopen ("/lib/libm.so.1", RTLD_LAZY);    if (!handle) {                                        err=dlerror();        perror(err);        exit(1);                                      }                                                 myfunc = dlsym(handle, "sin");                    if ((err = dlerror()) != NULL)  {                   perror(err);        exit(1);                                      }                                                 printf("sin of 1 is:%f\n", (*myfunc)(1.));                  dlclose(handle);                return 0;                  }                                                 


I know it has been 8 years but still...

Delay load is not supported out out the box on GNU systems but you can mimic it yourself by creating a small static stub which provides all necessary symbols and dlopens real implementation on first call (or even at program startup). Such stub can be written by hand, generated by project-specific script or via Implib.so tool:

# Replace$ gcc -o foo foo.c -lversion# with$ implib-gen.py libversion.so$ gcc -o foo foo.c libversion.tramp.S libversion.init.c