0

我真的很讨厌在这里问问题。但是我一直在查看其他一些帖子,并且诸如此类的解决方案似乎不起作用。这可能是我对语法的误解。

我正在改进我的一些旧代码。问题中的函数循环通过一些加载的模块并运行一个函数。当我在 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

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

4

1 回答 1

3

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

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

于 2011-08-11T01:26:55.730 回答