c - 如何判断一个so文件是否已经加载?

标签 c linux windows dll shared-libraries

我有两个共享库:a.so 和 b.so。

a.so 必须在 b.so 加载之前加载。而且,a.so 可能会被其他模块加载,而不是由我加载。

因此,我想在调用 dlopen("b.so", ...) 之前确定 a.so 是否已经加载。

在 Windows 下,我可以使用 GetModuleHandle("a.dll") 通过检查返回值来确定它。即如果返回值不为null则说明a.dll已加载;否则它还没有加载。

Linux下有类似GetModuleHandle的函数吗?

最佳答案

您实际上可以使用 dlopen使用 RTLD_NOLOAD 标志进行检查:

Don't load the library. This can be used to test if the library is already resident (dlopen() returns NULL if it is not, or the library's handle if it is resident).

关于c - 如何判断一个so文件是否已经加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357838/

相关文章:

c - 用 C 实现同步数据结构

ruby-on-rails - 如何搜索看起来像上传图片的图片

windows - Win32 : CreateDialog instead of multiple calls to CreateWindow - any downsides?

c++ - 扫描进程并在找到特定进程时执行某些操作

windows - 管理用户的 Schtasks 权限错误?

c - 退出时清理线程

android - 如何将 native 库加载到 native android 代码中? (安卓工作室)

c - RFID RC522读卡接线Pi

linux - 在某些文件夹名称中搜索特定文本字符串 - Linux 2.6

c++ - 在包含 500,000 个文件的目录中快速访问文件