graphics.h 在开发 C++ 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27341363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
graphics.h is not working in dev c++
提问by Avni Singh
I am trying to use graphics.h in dev C++ 5.7.1.
我正在尝试在 dev C++ 5.7.1 中使用 graphics.h。
I already searched the internet for the available options. I downloaded the graphics.h library in the include folder and chose the following in the parameters option:
我已经在互联网上搜索了可用的选项。我下载了包含文件夹中的 graphics.h 库,并在参数选项中选择了以下内容:
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
Still I cannot figure out why is it showing me these errors:
我仍然无法弄清楚为什么它会向我显示这些错误:
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.
This is my code:
这是我的代码:
#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;
}
回答by Saravanabalagi Ramachandran
Download following files to the directories mentioned:
将以下文件下载到提到的目录:
Here I assume you installed Dev-Cpp toC:\Dev-Cpp
这里我假设你安装了 Dev-CppC:\Dev-Cpp
http://www.cs.colorado.edu/~main/bgi/dev-c++/graphics.hDirectory:> C:\Dev-Cpp\include http://www.cs.colorado.edu/~main/bgi/dev-c++/libbgi.aDirectory:> C:\Dev-Cpp\lib
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
Create a new C++ project and set "Project Options->Parameters->Linker" as
创建一个新的 C++ 项目并将“项目选项->参数->链接器”设置为
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
and try executing this sample code; then go for the code that you posted above.
并尝试执行此示例代码;然后查找您在上面发布的代码。
#include<graphics.h>
int main( ){
initwindow( 700 , 700 , "MY First Program");
circle(200, 200, 150);
getch();
return 0;
}
回答by Amadeus
The error messages indicate that the function is not defined. Functions are typically defined in the source code or a library (static or dynamic.) Therefore, you need to either include the source code in your project so that it's linked along with your code above, or you will need to link to the precompiled library (perhaps an .a, .lib, or .dll file.)
错误消息表明该函数未定义。函数通常在源代码或库(静态或动态)中定义。因此,您需要将源代码包含在您的项目中,以便与上面的代码链接,或者您需要链接到预编译库(可能是 .a、.lib 或 .dll 文件。)
I'm not overly familiar with the library you're using; however, I would assume that graphics.h includes the function declarations and does not include function definitions.
我不太熟悉你使用的库;但是,我会假设 graphics.h 包含函数声明而不包含函数定义。
回答by kmx
This is linker error. Make sure library names you wrote in Project Options->Parameters->Linkerstart with "-".
这是链接器错误。确保您在Project Options->Parameters->Linker 中编写的库名称以“ -”开头。
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
as Zeke wrote above.
正如 Zeke 上面写的那样。