延迟加载相当于基于UNIX的系统 [英] Delay-Load equivalent in unix based systems

查看:164
本文介绍了延迟加载相当于基于UNIX的系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在延迟加载相当于基于Unix的系统。

What is the delay load equivalent in unix based system.

我有一个code Foo.cpp中,虽然用gcc编译我把它链接到共享对象(共有三种.so文件的存在。),每个不同的选项.so文件的。

I have a code foo.cpp, While compiling with gcc I link it to shared objects(totally three .so files are there.).Each of the .so file for different option.

./富-v 需要libversion.so
./富-update 需要libupdate.so

./foo -v needs libversion.so ./foo -update needs libupdate.so

我需要为这些库中的符号应只在运行时得到解决。

I need the symbol for those libraries should be resolved only at the run time.

./富-v如果libupdate.so库是不是应该不会收支平衡。

./foo -v should not break even if libupdate.so library is not there.

这是在Windows中使用(以DLL的属性)的延迟加载选项工作。什么是等值的UNIX系统。

It is working in windows using the delay load option(in properties of dll). What is its equivalent in unix systems.

将-lazy'选项的确在UNIX一样?
如果是这样,哪里有这个选项? (在生成文件或连接器ld)。

Will '-lazy' option does the same in UNIX?. If so,Where to include this option? (in makefile or with linker ld).

我不是UNIX好。
请帮助我..谢谢了。

I am not good in unix. Please help me.. Thanks in advance.

推荐答案

见的dlopen系统上的参考()。您可以手动打开库和在运行时,而不是在链接时解析外部符号。

See the reference on your system for dlopen(). You can manually open libraries and resolve external symbols at runtime rather than at link time.

翻出一个例子:

int main(int argc, char **argv) {                 
    void *handle=NULL;                                 
    double (*myfunc)(double);                     
    char *err=NULL;                                  

    handle = dlopen ("/lib/libm.so.1", RTLD_LAZY);
    if (!handle) {                                
        err=dlerror();
        perror(err);
        exit(1);                                  
    }                                             

    myfunc = dlsym(handle, "sin");                
    if ((err = dlerror()) != NULL)  {           
        perror(err);
        exit(1);                                  
    }                                             

    printf("sin of 1 is:%f\n", (*myfunc)(1.));              
    dlclose(handle);            
    return 0;                  
}                                                 

这篇关于延迟加载相当于基于UNIX的系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆