Creating a module system (dynamic loading) in C

前端 未结 9 1958
故里飘歌
故里飘歌 2020-12-12 12:53

How would one go about loading compiled C code at run time, and then calling functions within it? Not like simply calling exec().

EDIT: The the program loading the

9条回答
  •  情歌与酒
    2020-12-12 13:48

    Under Windows, this is how I do it:

    • Generate code (in C because it's easy to find compilers, and library requirements are minimal)
    • spawn a job to compile/link it into a DLL
    • load it with LoadLibrary
    • get function pointers with GetProcAddress

    The generate/compile/link steps generally take less than a second.

提交回复
热议问题