Alternatives to dlsym() and dlopen() in C++

后端 未结 5 821
北荒
北荒 2020-12-07 17:55

I have an application a part of which uses shared libraries. These libraries are linked at compile time.
At Runtime the loader expects the shared object to be in the <

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 18:55

    You are probably looking for some form of delay library load on Linux. It's not available out-of-the-box but you can easily mimic it by creating a small static stub library that would try to dlopen needed library on first call to any of it's functions (emitting diagnostic message and terminating if dlopen failed) and then forwarding all calls to it.

    Such stub libraries can be written by hand, generated by project/library-specific script or generated by universal tool Implib.so:

    $ implib-gen.py libxyz.so
    $ gcc myapp.c libxyz.tramp.S libxyz.init.c ...
    

提交回复
热议问题