【问题标题】:How do I get rid of the following error in DDA line Algorithm in Linux?如何摆脱 Linux 中 DDA 行算法中的以下错误?
【发布时间】:2016-03-13 22:09:20
【问题描述】:

文件line_3.c

#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

编译命令:

gcc line_3.c -o line_3 -lm

错误:

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

请帮忙

【问题讨论】:

  • 因为它需要 Borland TurboC 库和编译器?
  • Linux 上的控制台图形库是ncurses。您需要在 Ubuntu 中安装 ncurses 开发包 libncurses5-dev 以针对其 API 进行编译并链接库。然后你需要learn how to use it。您的 Borland TurboC 源代码需要大量修改。

标签: c linux gcc gcc-warning dda


【解决方案1】:

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

【讨论】:

  • 这个解决方案很有效,但你能解释一下为什么要删除 lgraph 吗?
【解决方案2】:

您的代码不完整,它不会像发布的那样编译。

代码使用一个可能来自 Borland 的 DOS 库来访问 DOS 图形显示卡。这是很老的,不能很好地翻译到 linux 环境。

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

【讨论】:

  • 您认为学习 Linux 特定图形 API 的最佳方式是什么。谢谢。
猜你喜欢
  • 1970-01-01
  • 2022-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多