没有实现类程序的定义

Mig*_*tes 31 c x11 gcc motif ld

我只是想分享一下我是如何找到错误的解决方案的

没有实现类程序的定义

运行X/Motif C应用程序时.我发布这个是因为我在网上搜索时只发现了一个对此问题的引用,并且它没有包含任何解决方案.

我设法解决了这个问题,如果你再次遇到这个问题,我想分享我的发现(注意:我不是说我的解决方案总能解决这类错误).

问题

我在运行使用Motif和X Intrinsics工具包的简单C程序时发现了这个问题.

$ gcc -Wall -c push.c
$ gcc -Wall -o push push.o -lXt -lXm
$ ./push
Error: No realize class procedure defined
Run Code Online (Sandbox Code Playgroud)

C源代码如下:

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

/* Prototype Callback function */
void pushed_fn(Widget, XtPointer, XmPushButtonCallbackStruct *);

int main(int argc, char **argv)
{
  Widget top_wid, button;
  XtAppContext  app;
  Display* display;

  XtToolkitInitialize();
  app = XtCreateApplicationContext();
  display = XtOpenDisplay(app, "localhost:10.0","push","push", NULL,0, &argc,argv);
  top_wid = XtAppCreateShell(NULL, "Form", applicationShellWidgetClass, display, NULL, 0);

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

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

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

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

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

Mig*_*tes 28

我怀疑问题可能在libXt上,因为XtRealizeWidget符号是在该库中定义的.我用nm观察它但看起来都很好:

$ nm -D /usr/lib/libXt.so |grep XtRealizeWidget
02b39870 T XtRealizeWidget
Run Code Online (Sandbox Code Playgroud)

"T"表示符号位于组成libXt库的目标文件的文本(代码)部分中,因此定义了此符号.系统库的路径也是正确的,我只有一个版本的libXt.

然后我认为将库传递给gcc链接器的顺序可能是原因并开始阅读它,最后在这个stackoverflow线程上

将库的顺序切换为:

$ gcc -Wall -o push push.o -lXm -lXt
Run Code Online (Sandbox Code Playgroud)

问题解决了.

注意库和传递给链接器的顺序!