How would a loaded library function call a symbol in the main application?

后端 未结 3 1378
春和景丽
春和景丽 2020-12-25 09:15

When loaded a shared library is opened via the function dlopen(), is there a way for it to call functions in main program?

3条回答
  •  甜味超标
    2020-12-25 09:40

    The dlopen() function, as discussed by @litb, is primarily provided on systems using ELF format object files. It is rather powerful and will let you control whether symbols referenced by the loaded library can be satisfied from the main program, and generally does let them be satisfied. Not all shared library loading systems are as flexible - be aware if it comes to porting your code.

    The callback mechanism outlined by @hhafez works now that the kinks in that code are straightened out.

提交回复
热议问题