[转]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
CFBundleroutines to load and unload executable code, becauseCFBundledoes not natively support the Objective-C runtime.NSBundlecorrectly 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,
NSBundlecannot 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 ...
随机推荐
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(8)-DbSession线程内唯一
原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(8)-DbSession线程内唯一 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 ...
- 绑定枚举到dropdownlist
pageTools.BindEnumToDropdownList(typeof(enumDealerArea), ddlBmwArea, new ListItem("--请选择--" ...
- jQuery本身方法($.each,$.map,$.contains,$ajax)
常用工具方法 (1)$.trim $.trim方法用于移除字符串头部和尾部多余的空格. $.trim(' Hello ') // Hello (2)$.contains $.contains方法返回一 ...
- linux_redhat_线程后台运行方法
建议看完1:后直接看2 screen 方式熟练些可靠. 次方法适用于redhat系统,unbunt* 系统用screen 命令 产看系统版本 cat /proc/version 首先项目制作的sh文件 ...
- JavaScript & XML
原文:JavaScript & XML 检测浏览器能力特性 //检测浏览器是否支持DOM2级XML var hasXmlDom = document.implementation.hasFea ...
- Android Permission denied 错误 ( 附Android权限大全 )
Android Permission denied 错误(附Android权限大全) java.net.SocketException: Permission denied (maybe missin ...
- [ 流行的网络框架 ] AFN & ASI
1.AFN & ASI(早已经停止更新,但现在许多公司也在使用.) AFNetWorking地址:https://github.com/AFNetworking/AFNetworking AS ...
- 【百度地图API】情人节求爱大作战——添加标注功能
原文:[百度地图API]情人节求爱大作战--添加标注功能 任务描述: 2月2日是除夕,2月14立马来!即将到来的情人节,你想送TA一份什么礼物呢? 不如,在你们居住的地方,画个大大的桃心,表达你对TA ...
- Socket 由浅入深系列--------- 简单实现编程(三)
socket 由浅入深 原理(一)介绍了一些,以下也就是简单实现,并未考虑其它性能化! 使用TCP的server客户机举例 server 设置一个简单的TCPserver涉及下列步骤: 调用 sock ...
- C#中WebBrowser的使用
原文:C#中WebBrowser的使用 其实网络上这类文章很多,我大致从头说说我自己的经验. 1.加入引用 在控件栏按右键,选择“添加/移除项”,选COM组件,选中“Microsoft Web Bro ...