简体   繁体   English

如何解决Linux Graphics C程序中的以下错误?

[英]How do I solve the following error in Linux Graphics C program?

I am trying to compile the following code,but it gives me a error message as listed below. 我正在尝试编译以下代码,但是它给我一条错误消息,如下所示。 I am a beginner in linux c graphics and cannot figure it out. 我是linux c图形的初学者,无法弄清楚。 Can anyone suggest a solution? 谁能提出解决方案?

code: 码:

#include<stdio.h>
#include<graphics.h>
void main()
{
      int gd = DETECT, gm;
      int dx, dy, p, end;
      float x1, x2, y1, y2, x, y;
      initgraph(&gd, &gm,NULL);
      printf("Enter Value of X1: ");
      scanf("%f", &x1);
      printf("Enter Value of Y1: ");
      scanf("%f", &y1);
      printf("Enter Value of X2: ");
      scanf("%f", &x2);
      printf("Enter Value of Y2: ");
      scanf("%f", &y2);

      dx = abs(x1 - x2);
      dy = abs(y1 - y2);

      p = 2 * dy - dx;
      if(x1 > x2)
      {
            x = x2;
            y = y2;
            end = x1;
      }
      else
      {
            x = x1;
            y = y1;
            end = x2;
      }
      putpixel(x, y, 10);
      while(x < end)
      {
            x = x + 1;
            if(p < 0)
            {
                  p = p + 2 * dy;
            }
            else
            {
                  y = y + 1;
                  p = p + 2 * (dy - dx);
            }
            putpixel(x, y, 10);
      }
      getch();
      closegraph();
}

error message: 错误信息:

meshramsd@ubuntu:~/libgraph-1.0.2$ ./b
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

You can try using libsvga which seems to run fine on Linux Mint - I ran Mint under Virtualbox on a Mac with no problems. 您可以尝试使用似乎在Linux Mint上运行良好的libsvga我在Mac上的Virtualbox下运行Mint没问题。

I installed the following packages: 我安装了以下软件包:

sudo apt-get install svgalib-bin libsvga1 libsvga1-dev

And then I hacked your code into the following: 然后,我将您的代码入侵了以下代码:

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <vga.h>
#include<stdio.h>

void main()
{
   int dx, dy, p, end;

   /* detect the chipset and give up supervisor rights */
   if (vga_init() < 0)
        return EXIT_FAILURE;

   vga_setmode(G1024x768x256);  /* some low resolution dont work */ 
   vga_setcolor(14);         /* color of pixel */

   float x1, x2, y1, y2, x, y;
   x1=10;
   y1=40;
   x2=800;
   y2=500;

   dx = abs(x1 - x2);
   dy = abs(y1 - y2);

   p = 2 * dy - dx;
   if(x1 > x2)
   {
       x = x2;
       y = y2;
       end = x1;
   } else {
       x = x1;
       y = y1;
       end = x2;
   }
   vga_drawpixel(x, y);
   while(x < end){
      x = x + 1;
      if(p < 0)
      {
         p = p + 2 * dy;
      } else {
         y = y + 1;
         p = p + 2 * (dy - dx);
      }
      vga_drawpixel(x, y);
   }
   sleep(10);

   /* restore textmode and fall back to ordinary text console handling */
   vga_setmode(TEXT);

}

I compiled like this: 我这样编译:

gcc graphics.c -lvga -lm -o graphics

and ran with: 并运行:

sudo ./graphics

I got this output - you can change the numbers easily enough if you want a different colour or size. 我得到了这个输出-如果您想要其他颜色或大小,可以轻松地更改数字。

在此处输入图片说明

I found this error, when I was doing graphics code in c on ubuntu 18.04. 我在ubuntu 18.04上的c中执行图形代码时发现了此错误。 I searched a lot but there was no satisfactory answer for this Issue. 我进行了很多搜索,但是没有找到满意的答案。 finally I read this Error so many time and found some this first line of error. 最终,我读了很多次此错误,并发现了第一行错误。

"[xcb] Unknown sequence number while processing queue" . “ [xcb]处理队列时未知的序列号”。

Code With Error 错误代码

#include <stdio.h>
#include <graphics.h>

int main() {

int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;

initgraph(&gd,&gm,NULL);  // I found Error here  Initialized Graph before standard input 
printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
    step=dx;
else
    step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
    putpixel(x,y,5);
    x=x+dx;
    y=y+dy;
    i++;
    delay(100);
}
getchar();
closegraph();
return 0;
}

Error Free Code 无错误代码

#include <stdio.h>
#include <graphics.h>

int main() {
int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;


printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

initgraph(&gd,&gm,NULL); //after correction I initialized graph after standard input

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
    step=dx;
else
    step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
    putpixel(x,y,5);
    x=x+dx;
    y=y+dy;
    i++;
    delay(100);
}
getchar();
closegraph();
return 0;
}

After successful execution i got my desired output 成功执行后,我得到了所需的输出 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linux上的这个GCC错误是什么,我该如何解决? gcc:内部编译器错误:非法指令(程序为) - What is this GCC error on Linux, and how do I solve it? gcc: internal compiler error: Illegal instruction (program as) 如何解决代码块无法正确运行图形 c 程序 - how to solve codeblocks unable to run a graphics c program properly c程序图形错误 - c program graphics error 如何解决 C 中的 CPU 调度模拟程序中的分段错误(核心转储)错误? - How do I solve Segmentation Fault (Core Dump) error in my CPU Scheduling Simulation program in C? C C++ 图形程序Linux - C C++ Graphics program in Linux 我如何知道在Linux上编写的C程序是否可以在其他地方使用 - How do I know if a C program will written on Linux will work elsewhere 我如何在ac程序中接收以sigqueue发送的信号(在Linux上)? - How do I receive a signal sent with sigqueue in a c program (on linux)? 如何在基于Linux的系统上的c程序中使用mqueue? - How do I use mqueue in a c program on a Linux based system? 如何在 Linux 上运行以下 C 程序“寻求导师” - How to run the following C program "Seeking Tutor" on Linux 如何解决此 C 程序中的类型重定义错误 - how to solve type redefinition error in this C program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM