我只是X-Windows的新手,并尝试在Linux上调用简单的MessageBox,就像Window一样。
我在Ubuntu 12.04LTS 64bit上安装了Netbeans完整版。 我在这个项目中包含了“/ usr / include / Xm”,对于libs,我包含了“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");
}
答案 0 :(得分:2)
XtAddCallback
期望XtCallbackProc
您的pushed_fn
可能兼容,但它不是XtCallbackProc,因为它直接使用Xm类型。
自从我做了Motif以来已经有一段时间了,所以我可能错了,但解决办法可能是:
void pushed_fn(Widget w, XtPointer client, XtPointer cbsXt)
{
XmPushButtonCallbackStruct *cbs = (XmPushButtonCallbackStruct*)cbsXt;
...
}