[转]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 ...
随机推荐
- 学习javascript 的一点感想
原文:学习javascript 的一点感想 //动态性是指,在一个Javascript对象中,要为一个属性赋值,我们不必事先创建一个字段,只需要在使用的时候做赋值操作即可,如下例:var obj=ne ...
- oracle_修改Oracle数据库字符集 AL32UTF8;
修改数据库字符集 以支持维文等 utf8 停掉库 进入装载模式 ALTER SYSTEM ENABLE RESTRICTED SESSION; ALTER SYSTEM SET JOB_QUEUE_ ...
- IOS SDK相机的详细解释/画廊(默认+他们的高清摄像头接口)
原版的blog,转载请注明出处 blog.csdn.net/hello_hwc 前言: 新NSURLSession的UploadTask的,结果写那个Demo的时候想要写成拍照上传.然后就想到先写一个 ...
- 【转】Android 常用 adb 命令总结
原文地址:http://testerhome.com/topics/2565 针对移动端 Android 的测试, adb 命令是很重要的一个点,必须将常用的 adb 命令熟记于心, 将会为 Andr ...
- 【百度地图API】——国内首款团购网站的地图插件
原文:[百度地图API]--国内首款团购网站的地图插件 摘要: 本文介绍了一款应用在团购网站上的地图插件,适用于目前非常流行的团购网站.使用这款地图插件,无需任何编程技术,你就把商家的位置轻松地标注在 ...
- windows下exfat无法写入修复
为了可以实现mac与windows文件共享,把移动硬盘格式化为exfat了,但是在osx中放入文件后,在windows上紧进行读取写入时出现错误,提示使用chkdsk进行修正,以下是修正步骤. ①wi ...
- (c#2.0)serialPort串口通讯
原文:(c#2.0)serialPort串口通讯 using System; using System.Collections.Generic; using System.ComponentModel ...
- Android自动化测试框架新书:交流
大家觉得编写一本描述MonkeyRunner原理分析的书籍如何?估计大概10万字左右.内容大概分布如下: Monkey实现原理: 去描述运行在目标安卓机器的monkey是如何运行并处理MonkeyRu ...
- CSS知识总结之浏览器(持续更新)
web页面浏览器渲染过程 1.解析html文件,并构建DOM树: 在DOM树中,每一个html标签都有一个对应的节点,并且每一个文本也有一个对应 的节点(js的textNode),DOM树的根节点就是 ...
- Fedora 20 Gnome安装及配置记录
下载了F20的Gnome版,原先安装的是19KDE的,原因是昨晚看书,觉得电脑开着也没什么事情,倒不如看看能不能升级或下载点东西 原先是KDE的界面,所以打算换换风格,使用下Gnome,不过更换过程总 ...