dlopen与dlsym用法
包含头文件:
#include <dlfcn.h>
函数定义:
void * dlopen( const char * pathname, int mode );
函数描述:
在dlopen的()函数以指定模式打开指定的动态连接库文件,并返回一个句柄给调用进程。通过这个句柄来使用库中的函数和类。使用dlclose
mode:分为这两种
RTLD_LAZY 暂缓决定,等有需要时再解出符号
RTLD_NOW 立即决定,返回前解除所有未决定的符号。
RTLD_LOCAL
RTLD_GLOBAL 允许导出符号
RTLD_GROUP
RTLD_WORLD
返回值:
打开错误返回NULL
成功,返回库引用
编译时候要加入 -ldl (指定dl库)
函数原型是
void* dlsym(void* handle,const char* symbol)
该函数在<dlfcn.h>文件中。
hello(); |
注意库函数在库中的定义要用extern“c”来申明,这样在主函数中才能通过“hello”来查找函数。申明的方式有以下两种:
extern "C" |
导入类库方法:
#include void* triangle= dlopen("./triangle.so", RTLD_LAZY); destroy_t* destroy_triangle poly->set_side_length(7); destroy_triangle(poly); // unload the triangle library dlclose(triangle); |
最新文章
- nginx下搭建CodeIgniter问题集锦
- HDFS Federation (读书笔记)
- php 图片添加文字水印 以及 图片合成(微信快码传播)
- Socket常见错误
- ruby学习总结04
- shell编程之数学运算
- iostat详解
- IO库 8.1
- PHP控制连接打印机
- python基础教程(四)
- Android 软键盘的显示和隐藏,这样操作就对了
- MySQL升级-5.6升级到5.7版本&;切换GTID模式
- 我的第三篇博客(激动激动真激动!!!)A-B Problem
- Jenkins结合.net平台工具之Msbuild
- amoeba读写分离
- Xtreme8.0 - Kabloom 动态规划
- JavaScript部分兼容性函数
- php各种主流框架的优缺点
- js模块化的总结
- 【Android】5.5 状态切换(Switch)和评级条(RatingBar)
热门文章
- 用Merge存储引擎中间件实现MySQL分表
- Kefa and Watch
- 2 pyspark学习----基本操作
- java 关于getProperty()方法中反斜杠问题
- GIL 已经被杀死了么?
- 451. Sort Characters By Frequency (sort map)
- [Xcode 实际操作]二、视图与手势-(5)给图像视图添加圆角效果
- Luogu P1074靶形数独【搜索/剪枝】By cellur925
- 【MySQL】全量+增量的备份/恢复
- luoguP4242树上的毒瘤