在 C 中创建模块系统(动态加载) [英] Creating a module system (dynamic loading) in C
本文介绍了在 C 中创建模块系统(动态加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在运行时加载已编译的 C 代码,然后在其中调用函数?不像简单地调用 exec().
How would one go about loading compiled C code at run time, and then calling functions within it? Not like simply calling exec().
加载模块的程序是用 C 语言编写的.
The the program loading the module is in C.
推荐答案
在 Linux/UNIX 中你可以使用 POSIX dlopen
/dlsym
/dlerror
/dlclose
函数来动态打开共享库并访问它们提供的符号(包括函数),参见手册页了解详情.
In Linux/UNIX you can use the POSIX dlopen
/ dlsym
/ dlerror
/ dlclose
functions to dynamically open shared libraries and access the symbols (including functions) they provide, see the man page for details.
这篇关于在 C 中创建模块系统(动态加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文