0

我只是 X-Windows 的新手,并尝试编写只在 Linux 上调用简单 MessageBox 的代码,如 Window 的。

我在 Ubuntu 12.04LTS 64bit 上并安装了 Netbeans 完整版。我在这个项目中包含了“/usr/include/Xm”,对于库,我包含了“Motif”库。

编译代码时出现以下错误:

main.cpp:24:63: error: invalid conversion from ‘void (*)(Widget, XtPointer, XmPushButtonCallbackStruct*) {aka void (*)(_WidgetRec*, void*, XmPushButtonCallbackStruct*)}’ to ‘XtCallbackProc {aka void (*)(_WidgetRec*, void*, void*)}’ [-fpermissive]
/usr/include/X11/Intrinsic.h:1241:13: error:   initializing argument 3 of ‘void XtAddCallback(Widget, const char*, XtCallbackProc, XtPointer)’ [-fpermissive] 

我真的不明白这个错误,至少我从未见过像“aka void blah blah~~”这样的语法。

谁能帮我解决这个编译错误,如果可能的话,请解释一下这个错误消息的含义?

以下是原始源代码:

#include <Xm/Xm.h> 
#include <Xm/PushB.h>

/* Prototype Callback function */

void pushed_fn(Widget , XtPointer , 
               XmPushButtonCallbackStruct *);


main(int argc, char **argv) 

{   Widget top_wid, button;
    XtAppContext  app;

    top_wid = XtVaAppInitialize(&app, "Push", NULL, 0,
        &argc, argv, NULL, NULL);

    button = XmCreatePushButton(top_wid, "Push_me", NULL, 0);

    /* tell Xt to manage button */
                XtManageChild(button);

                /* attach fn to widget */
    XtAddCallback(button, XmNactivateCallback, pushed_fn, NULL);

    XtRealizeWidget(top_wid); /* display widget hierarchy */
    XtAppMainLoop(app); /* enter processing loop */ 

}

void pushed_fn(Widget w, XtPointer client_data, 
               XmPushButtonCallbackStruct *cbs) 
  {   
     printf("Don't Push Me!!\n");
  }
4

1 回答 1

2

XtAddCallback期望XtCallbackProcYour pushed_fnmay be compatible,但它不是 XtCallbackProc 因为它直接使用 Xm 类型。

自从我完成 Motif 以来已经有一段时间了,所以我可能是错的,但解决方案可能是:

void pushed_fn(Widget w, XtPointer client, XtPointer cbsXt)
{
    XmPushButtonCallbackStruct *cbs = (XmPushButtonCallbackStruct*)cbsXt;
    ...
}
于 2013-08-26T06:36:10.723 回答