[转]unload dynamic library needs two dlclose() calls?
src: http://stackoverflow.com/questions/8793099/unload-dynamic-library-needs-two-dlclose-calls
Question:
I have a dynamic library which I load using dlopen()
and then unload using dlclose()
;
If I dont include any objective c code dlopen()
needs one dlclose()
call which is expected behavior. But when I include any objective c code to target, I have problem that I need to do two dlclose()
calls to the loaded library in order to unload.
Is this something expected behavior? How can I fix it?
Answer:
I realize that you are using dlopen
, not CFBundle
or NSBundle
. Nevertheless, the Code Loading Programming Topics manual says this:
In Cocoa applications, you should not use
CFBundle
routines to load and unload executable code, becauseCFBundle
does not natively support the Objective-C runtime.NSBundle
correctly loads Objective-C symbols into the runtime system, but there is no way to unload Cocoa bundles once loaded due to a runtime limitation.
and this:
Because of a limitation in the Objective-C runtime system,
NSBundle
cannot unload executable code.
This makes me suspect that when you load your library, it registers itself with the Objective-C runtime, and the runtime calls dlopen
on the library again (or somehow increases the library's reference count).
I searched the Objective-C runtime source code and found this:
// dylibs are not allowed to unload// ...except those with image_info and nothing else (5359412)if(result->mhdr->filetype == MH_DYLIB && _hasObjcContents(result)){
dlopen(result->os.dl_info.dli_fname, RTLD_NOLOAD);}
So yes, the Objective-C runtime is calling dlopen
on your library specifically to prevent it from being unloaded. If you cheat and call dlclose
twice, you should expect bad things to happen.
[转]unload dynamic library needs two dlclose() calls?的更多相关文章
- Dynamic Library Design Guidelines
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100 ...
- [工作积累] Android dynamic library & JNI_OnLoad
Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux) so a explici ...
- PHP Startup: Unable to load dynamic library
昨天帮一朋友配置服务器结果发现apache日志中有PHP Warning: PHP Startup: Unable to load dynamic library 提示了,然后调试数据库连接发现提示C ...
- PHP启动:动态库加载失败(PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/*.so')
今天在linux上面智障一般搞了好久,本来想安装个swoole的,然后用 php -m 的命令想看下安装的PHP扩展库,发现有的扩展库有的可以出来,有的加载失败, 加载失败的错误类型: PHP Wa ...
- 安装完 swoole 后出现 PHP Warning: PHP Startup: Unable to load dynamic library 'swoole.so'的解决方法
安装完 swoole 后出现 PHP Warning: PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /home/s ...
- ***XAMPP:报错 Unable to load dynamic library的解决方法
A PHP Error was encountered Severity: Core Warning Message: PHP Startup: Unable to load dynamic libr ...
- A simple dynamic library implemented in C# 4.0 to deal with XML structure
https://github.com/cardinals/XmlToObjectParser A simple dynamic library implemented in C# 4.0 to dea ...
- Unable to load dynamic library 'zip.so' on Centos 6.8 useing php7.3
背景: Centos6.8服务器升级php版本,从7.1升级到7.3,常用扩展都安装完成之后,报:Class 'ZipArchive' not found.一看就是zip扩展没有,需要手动安装了. 中 ...
- tensorflow2.x 报错 Could not load dynamic library 'cudart64_101.dll'
当我们使用 tensorflow 最新版本的时候 ,会出现这样的错误 -- ::] Could not load dynamic library 'cudart64_101.dll'; dlerror ...
随机推荐
- VS2013打包部署(图解)
首先要说明的是VS解决方案的配置Debug模式和Release有什么区别模式.Debug模式通常被称为调试模式,它包括调试信息,不优化的代码,序:Release模式通常叫做公布模式.不包括调试信息,可 ...
- int 价值型追记-time
一个 30 M 的int号码值一次性保存.和读取一次,避免保存为char 种类,进行格转变,格转换时间是非常耗时. #include <iostream> #include <fst ...
- Swift-开发 # 1.2版本迁移
{ Parallels: 可以将一个win程序拖到mac中运行. } --类似于虚拟机 遇到的几大问题: 1.自动修改无效? --忽略它的存在,坑. 2.无止境的修改,还是错? --使用替换工具-&g ...
- mysql 数据库插入语句之insert into,replace into ,insert ignore
近期才发现mysql的插入语句竟然有如此多的使用方法,这里拿来分享一下. ①关于insert into : insert into table_name values(); insert into t ...
- XP 多国语言包
http://download.microsoft.com/download/f/6/4/f648c363-6975-470c-8202-ac5aea706109/WindowsXP-KB835935 ...
- Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source
1. A2DP Introduction The Advanced Audio Distribution Profile (A2DP) defines the protocols and proced ...
- installshield制作的安装包卸载时提示重启动的原因以及解决办法
原文:installshield制作的安装包卸载时提示重启动的原因以及解决办法 有时候卸载installshield制作的安装包程序,卸载完会提示是否重启电脑以完成所有卸载,产生这个提示的常见原因有如 ...
- Python 图论工具
networkx: 一个用Python语言开发的图论与复杂网络建模工具, 内置了经常使用的图与复杂网络分析算法, 能够方便的进行复杂网络数据分析.仿真建模等工作. 依赖工具: numpy pypar ...
- ASP.NET 5中的Sake与KoreBuild
初识ASP.NET 5中的Sake与KoreBuild 从github上签出基于ASP.NET 5的MVC 6的源代码进行编译,发现有2个编译命令: build.cmd是针对Windows的编译命 ...
- WeChatAPI 开源系统架构详解
WeChatAPI 开源系统架构详解 如果使用WeChatAPI,它扮演着什么样的角色? 从图中我们可以看到主要分为3个部分: 1.业务系统 2.WeChatAPI: WeChatWebAPI,主要是 ...