
1.静态链接库
2.动态链接库
3.动态加载库
其中1,2都是在编程时直接调用,在链接时加参数-l进行链接
第三种需要在编程时使用dlopen等函数来获取库里面函数的定义,然后进行调用.
不过对于没有提供头文件的动态库,只能dlopen等函数来调用
调用dlopen时,如果之前加载过,则返回同样的句柄,并会标记reference计数加1,因此相对应的需要相同多次数的dlclose才能释放。If the same library is loaded again with dlopen(), the same file handle is returned. The dl library maintains reference counts for library handles, so a dynamic library is not deallocated until dlclose() has been called on it as many times as dlopen() has succeeded on it.
在dlopen()函数以指定模式打开指定的动态链接库文件,并返回一个句柄给dlsym()的调用进程。使用dlclose()来卸载打开的库。当库被装入后,可以把 dlopen() 返回的句柄作为给 dlsym() 的第一个参数,以获得符号在库中的地址。使用这个地址,就可以获得库中特定函数的指针,并且调用装载库中的相应函数。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)