gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:07 26 4
gpt4 key购买 nike

文件 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

请帮忙

最佳答案

您无需做太多事情,只需将其编译为'gcc line_3.c -o line_3 -lgraph',您一定会得到答案。所有这些显示错误的函数都是 lgraph 包。 :)

关于c - 如何消除 Linux 中 DDA 行算法中的以下错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35976493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com