gpt4 book ai didi

c++ - 使用 graphics.h 时 undefined reference ?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:41:40 24 4
gpt4 key购买 nike

我正在尝试在开发 C++ 5.7.1 中使用 graphics.h。

我已经在互联网上搜索了可用的选项。我在包含文件夹中下载了 graphics.h 库,并在参数选项中选择了以下内容:

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

我仍然不明白为什么它会向我显示这些错误:

undefined reference to `initgraph'
undefined reference to `graphresult'
undefined reference to `grapherrormsg'
undefined reference to `getmaxx'
undefined reference to `getmaxy'
undefined reference to `getmaxcolor'
undefined reference to `getcolor'
undefined reference to `circle'
undefined reference to `closegraph'
[Error] ld returned 1 exit status.

这是我的代码:

#include<iostream>
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
//#include<conio>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int radius = 100;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\include\\winbgim");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* draw the circle */
circle(midx, midy, radius);
/* clean up */
getch();
closegraph();
return 0;
}

最佳答案

将以下文件下载到提到的目录:

这里我假设你安装了 Dev-Cpp 到 C:\Dev-Cpp

http://www.cs.colorado.edu/~main/bgi/dev-c++/graphics.h目录:> C:\Dev-Cpp\include http://www.cs.colorado.edu/~main/bgi/dev-c++/libbgi.a目录:> C:\Dev-Cpp\lib

创建一个新的C++项目并设置“Project Options->Parameters->Linker”为

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

并尝试执行此示例代码;然后找到您在上面发布的代码。

#include<graphics.h>

int main( ){
initwindow( 700 , 700 , "MY First Program");
circle(200, 200, 150);
getch();
return 0;
}

关于c++ - 使用 graphics.h 时 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27341363/

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