插入库:XOpenDisplay

发布于 2024-08-16 09:48:49 字数 1641 浏览 7 评论 0原文

我正在开发一个项目,需要更改 X11/Xlib.h 中定义的 XOpenDisplay 函数的行为。

我找到了一个 示例,它应该完全符合我的要求我正在寻找,但是当我编译它时,我收到以下错误消息:

XOpenDisplay_interpose.c:14:错误:“XOpenDisplay”的类型冲突 /usr/include/X11/Xlib.h:1507:错误:之前的“XOpenDisplay”声明位于此处

谁能帮我解决这个问题?我缺少什么?

到目前为止我的程序代码 - 基于上面提到的示例:

#include <stdio.h>
#include <X11/Xlib.h>
#include <dlfcn.h>

Display *XOpenDisplay(char *display_name)
{
  static Display *(*func)(char *);
  Display *ret;
  void* handle=NULL;
  handle = dlopen ("XOpenDisplay_interpose.so", RTLD_LAZY);

  if(!handle){
      fprintf(stderr, "ERROR dlopen\n");
  }

  if(!func)
    func = (Display *(*)(char *))dlsym(handle,"XOpenDisplay");

  if(display_name)
    printf("XOpenDisplay() is called with display_name=%s\n", display_name);
  else
    printf("XOpenDisplay() is called with display_name=NULL\n");

  ret = func(display_name);
  printf("  calling XOpenDisplay(NULL)\n");
  ret = func(0);
  printf("XOpenDisplay() returned %p\n", ret);

  return(ret);
}

int XCloseDisplay(Display *display_name)
{ 
  static int (*func)(Display *); 
  int ret; 
  void* handle=NULL;
  handle = dlopen ("XOpenDisplay_interpose.so", RTLD_LAZY);
  if(!handle){
   fprintf(stderr, "ERROR dlopen\n");
  }

  if(!func)
    func = (int (*)(Display *))dlsym(handle,"XCloseDisplay"); 

  ret = (int)func(display_name); 

  printf("called XCloseDisplay(%p)\n", display_name); 

  return(ret); 
}

int main()
{
}

问候, 安迪.

I am working on a project where I need to change the behaviour of the XOpenDisplay function defined in X11/Xlib.h.

I have found an example, which should do exactly what I am looking for, but when I compile it, I get the following error messages:

XOpenDisplay_interpose.c:14: Error: conflicting types for »XOpenDisplay«
/usr/include/X11/Xlib.h:1507: Error: previous declaration of »XOpenDisplay« was here

Can anyone help me with that problem? What am I missing?

My program code so far - based on the example mentioned above:

#include <stdio.h>
#include <X11/Xlib.h>
#include <dlfcn.h>

Display *XOpenDisplay(char *display_name)
{
  static Display *(*func)(char *);
  Display *ret;
  void* handle=NULL;
  handle = dlopen ("XOpenDisplay_interpose.so", RTLD_LAZY);

  if(!handle){
      fprintf(stderr, "ERROR dlopen\n");
  }

  if(!func)
    func = (Display *(*)(char *))dlsym(handle,"XOpenDisplay");

  if(display_name)
    printf("XOpenDisplay() is called with display_name=%s\n", display_name);
  else
    printf("XOpenDisplay() is called with display_name=NULL\n");

  ret = func(display_name);
  printf("  calling XOpenDisplay(NULL)\n");
  ret = func(0);
  printf("XOpenDisplay() returned %p\n", ret);

  return(ret);
}

int XCloseDisplay(Display *display_name)
{ 
  static int (*func)(Display *); 
  int ret; 
  void* handle=NULL;
  handle = dlopen ("XOpenDisplay_interpose.so", RTLD_LAZY);
  if(!handle){
   fprintf(stderr, "ERROR dlopen\n");
  }

  if(!func)
    func = (int (*)(Display *))dlsym(handle,"XCloseDisplay"); 

  ret = (int)func(display_name); 

  printf("called XCloseDisplay(%p)\n", display_name); 

  return(ret); 
}

int main()
{
}

Regards,
Andy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-08-23 09:48:49

声明如下:

Display *XOpenDisplay(_Xconst char *display_name)

所以只需添加一个“const”就足够了。

The declaration reads like this:

Display *XOpenDisplay(_Xconst char *display_name)

So just adding a 'const' should suffice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文