我有两个共享库: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()
returnsNULL
if it is not, or the library's handle if it is resident).
关于c - 如何判断一个so文件是否已经加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357838/