【问题标题】:Dlsym: cast to pointer from integer of different sizeDlsym:从不同大小的整数转换为指针
【发布时间】:2011-08-11 01:21:20
【问题描述】:

我真的很讨厌在这里提问。但我一直在看some of the other posts,像这样的解决方案似乎不起作用。这可能是我对语法的误解。

我正在改进我的一些旧代码。问题中的函数循环通过一些加载的模块并运行一个函数。当我在 x86 上时,这段代码运行得非常好,但跳转到 64 位时一切都搞砸了。

int FindCmd(ArgS *Args)
{   
    /* We need to check our loaded modules for the appropriate command. */
    int found = 0;

    ModS *Current;

    for(Current = Modules; Current != NULL; Current = Current->Next)    
    {   /* Cycle through the modules. */

        int (*OnConsoleCmd)(RootS *IRC, ArgS *Args, McapiS *Mcapi);

        /* The below statement is the problem. */
        OnConsoleCmd = (int (*)(RootS *, ArgS *, McapiS *))dlsym(Current->Handle, "OnConsoleCmd");
        /* The above statement is the problem. */

        if(OnConsoleCmd != NULL)
        {
            if(OnConsoleCmd(IRC, Args, Mcapi) != 0)     /* Run command. */
                found++;
        }
    }

    return found;
}

我收到以下警告:

exec/src/input.c:98:18: warning: cast to pointer from integer of different size

当然还有我的程序段错误。我知道这只是一个铸造问题,但我不知道一个简单且可移植的解决方案。如果您需要更多信息,请告诉我。谢谢。

【问题讨论】:

  • 你不应该讨厌在这里提问,这在很大程度上是这个网站的目的。
  • @dreamlax:讨厌不得不做和讨厌做是有区别的。讨厌不得不这样做意味着你对缺乏经验有建设性的不满。讨厌意味着你不愿意寻求真正需要改进的帮助。

标签: c dlsym


【解决方案1】:

这很可能是因为您在范围内没有dlsym() 的原型,因此它被隐式声明为int dlsym(),这是错误的。

如果您将#include <dlfcn.h> 添加到使用dlsym() 的文件中,您将获得正确的声明并且它应该可以工作。

【讨论】:

  • 是的,就是这样,我忘记了 。哇,好尴尬!无论如何,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 2014-02-14
相关资源
最近更新 更多