首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Linux中消除DDA行算法中的以下错误?

如何在Linux中消除DDA行算法中的以下错误?
EN

Stack Overflow用户
提问于 2016-03-13 22:09:20
回答 2查看 1K关注 0票数 0

文件line_3.c

代码语言:javascript
复制
#include <stdio.h>
//#include <dos.h>
#include <graphics.h>

void lineDDA(int, int, int, int);
void main() {
    int x1, y1, xn, yn;
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");
    printf("Enter the starting coordinates of line: ");
    scanf("%d %d", &x1, &y1);
    printf("Enter the ending coordinates of line: ");
    scanf("%d %d", &xn, &yn);
    lineDDA(x1, y1, xn, yn);
    getch();
}

void lineDDA(int x1, int y1, int xn, int yn) {
    int dx, dy, m, i;
    m = (yn - y1) / (xn - x1);
    for (i = x1; i <= xn; i++) {
        if (m <= 1) {
            dx = 1;
            dy = m * dx;
        } else {
            dy = 1;
            dx = dy / m;
        }
        x1 = x1 + dx;
        y1 = y1 + dy;
        putpixel(x1, y1, RED);
        delay(20);
    }
    //  MISSING CODE

汇编指挥部:

代码语言:javascript
复制
gcc line_3.c -o line_3 -lm

错误:

代码语言:javascript
复制
meshramsd@ubuntu:~$ gcc line_3.c -o line_3 -lm
/tmp/ccYuGyd4.o: In function `main':
line_3.c:(.text+0x23): undefined reference to `initgraph'
line_3.c:(.text+0x32): undefined reference to `grprintf'
line_3.c:(.text+0x4c): undefined reference to `grscanf'
line_3.c:(.text+0x5b): undefined reference to `grprintf'
line_3.c:(.text+0x75): undefined reference to `grscanf'
line_3.c:(.text+0x8d): undefined reference to `grgetch'
/tmp/ccYuGyd4.o: In function `lineDDA':
line_3.c:(.text+0x110): undefined reference to `putpixel'
line_3.c:(.text+0x11d): undefined reference to `delay'
collect2: error: ld returned 1 exit status

请帮帮忙

EN

回答 2

Stack Overflow用户

发布于 2016-09-19 08:53:21

你没什么可做的,只要把它编成“gcc line_3.c -o line_3 -lgraph”,你肯定会得到答案的。所有这些显示误差的函数都是图形包的。:)

票数 1
EN

Stack Overflow用户

发布于 2016-03-13 22:25:28

您的代码是不完整的,它不会按发布的方式编译。

该代码使用DOS库(可能来自Borland )访问DOS图形显示卡。这是非常古老的,不能很好地转化为linux环境。

要么自己提供所有图形函数的实现(不太可能),要么使用linux特定的图形API。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35976493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档