简体   繁体   English

代码块 graphics.h 不工作

[英]Codeblocks graphics.h not working

When I do:当我做:

#include <graphics.h>

It says:它说:

fatal error: graphics.h: No such file or directory致命错误:graphics.h:没有这样的文件或目录

How to fix this?如何解决这个问题?

I'm using codeblocks 16.01我正在使用代码块 16.01

Using the angle brackets "<>" assumes graphics.h is part of the C standard library.使用尖括号“<>”假定 graphics.h 是 C 标准库的一部分。 After some research, it appears this file is no longer included in the library.经过一些研究,该文件似乎不再包含在库中。 If you wish to continue using this library, you will have to find graphics.h and place it in the same location as your source code.如果你想继续使用这个库,你必须找到 graphics.h 并将它放在与你的源代码相同的位置。

In your source code, you will then write: #include "graphics.h"然后,在您的源代码中,您将编写: #include "graphics.h"

Step 1: Download graphics.h library from http://winbgim.codecutter.org/ or use this link .第 1 步:从http://winbgim.codecutter.org/下载 graphics.h 库或使用此链接

Step 2: Extract the downloaded file.第二步:解压下载的文件。 You'll get three files:你会得到三个文件:

graphics.h
winbgim.h
libbgi.a

Step 3: Copy and paste graphics.h and winbgim.h files into the include folder of your compiler directory.第 3 步:将 graphics.h 和 winbgim.h 文件复制并粘贴到编译器目录的 include 文件夹中。 (If you have Code::Blocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> MinGW >> include . Paste these two files there.) (如果您在计算机的 C 驱动器中安装了 Code::Blocks,请通过: Disk C >> Program Files >> CodeBlocks >> MinGW >> include 。将这两个文件粘贴到那里。)

Step 4: Copy and paste libbgi.a to the lib folder of your compiler directory.第 4 步:将 libbgi.a 复制并粘贴到编译器目录的 lib 文件夹中。

Step 5: Open Code::Blocks.第 5 步:打开 Code::Blocks。 Go to Settings >> Compiler >> Linker settings转到Settings >> Compiler >> Linker settings

Step 6: In that window, click the Add button under the “Link libraries” part, and browse and select the libbgi.a file copied to the lib folder in step 4.步骤 6:在该窗口中,单击“链接库”部分下的添加按钮,然后浏览并选择在步骤 4 中复制到 lib 文件夹的 libbgi.a 文件。

Step 7: Go to “Other linker options” on the right part and paste these commands:第 7 步:转到右侧的“其他链接器选项”并粘贴以下命令:

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

Step 8: Make sure you got steps 6 and 7 right!第 8 步:确保第 6 步和第 7 步正确! Here's a screenshot of previous two steps.这是前两个步骤的屏幕截图。 Then, click Ok.然后,单击确定。

Graphics.h in codeblocks - Compiler Settings
Global Compiler Settings >> Linker Settings

Step 9: If you now try compiling a graphics.h program code in C or C++, you'll still get error.第 9 步:如果你现在尝试用 C 或 C++ 编译 graphics.h 程序代码,你仍然会得到错误。 To solve it, open graphics.h file (pasted in include folder in step 3) with text editor.要解决此问题,请使用文本编辑器打开 graphics.h 文件(在步骤 3 中粘贴在包含文件夹中)。 Go to line number 302, and replace that line with this line:转到第 302 行,并将该行替换为以下行:

"int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX"

if it is correct(same as above) then leave it as it is如果它是正确的(与上面相同),则保持原样

Save the file.保存文件。 Done!完毕!

Now you can compile any C or C++ program containing graphics.现在您可以编译任何包含graphics. h header file. h头文件。 If you compile C codes, you'll still get an error saying: “fatal error: sstream : no such file directory” .如果你编译 C 代码,你仍然会得到一个错误提示: “fatal error: sstream : no such file directory” For this issue, if your file extension is .对于这个问题,如果您的文件扩展名为. c, change it to .cpp . c,将其更改为.cpp

paste the graphics.h and winbgim.h into C:\MinGW\include folder.将 graphics.h 和 winbgim.h 粘贴到 C:\MinGW\include 文件夹中。 Then paste libbgi.a to C:\MinGW\lib.然后将 libbgi.a 粘贴到 C:\MinGW\lib。 this solution will be worked.这个解决方案将起作用。 because your default compile's installation location set to C:\MinGW.因为您的默认编译安装位置设置为 C:\MinGW。 otherwise you can change your compile's installation location in codebolck.否则您可以在 codebolck 中更改编译器的安装位置。 Setting>> Global Compiler setting>> Toolchain executable设置>>全局编译器设置>>工具链可执行文件

I got a solution from here(You can refer this for more details): How to use graphics.h in code blocks?我从这里得到了一个解决方案(你可以参考这个以获得更多细节): 如何在代码块中使用 graphics.h?

Step 1: To setup “graphics.h” in CodeBlocks, first set up winBGIm graphics library.步骤 1:要在 CodeBlocks 中设置“graphics.h”,首先设置 winBGIm 图形库。 Download WinBGIm from Borland BGI emulation for MingW .从用于 MingW 的 Borland BGI 仿真下载 WinBGIm

Step 2: Extract the downloaded file.第二步:解压下载的文件。 There will be three files:会有三个文件:

1. graphics.h
2. winbgim.h
3. libbgi.a

Step 3: Copy and paste graphics.h and winbgim.h files into the include folder of compiler directory.步骤 3:将 graphics.h 和 winbgim.h 文件复制并粘贴到编译器目录的 include 文件夹中。 (If you have Code::Blocks installed in C drive of your computer, go through: Disk (如果您的计算机 C 盘中安装了 Code::Blocks,请通过:磁盘

C >> Program Files >> CodeBlocks >> MinGW >> include C >> 程序文件 >> 代码块 >> MinGW >> 包含

. . Paste these two files there.)将这两个文件粘贴到那里。)

Step 4: Copy and paste libbgi.a to the lib folder of compiler directory.第四步:将 libbgi.a 复制并粘贴到编译器目录的 lib 文件夹中。

Step 5: Open Code::Blocks.第 5 步:打开 Code::Blocks。 Go to

Settings >> Compiler >> Linker settings设置>>编译器>>链接器设置

. .

Step 6: In that window, click the Add button under the “ Link libraries ” part, and browse.第 6 步:在该窗口中,单击“链接库”部分下的添加按钮,然后浏览。

Select the libbgi.a file copied to the lib folder in step 4.选择步骤 4 中复制到 lib 文件夹的 libbgi.a 文件。

Step 7: In right part (ie. other linker options) paste commands第 7 步:在右侧(即其他链接器选项)粘贴命令

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

Step 8: Click Ok第 8 步:单击确定

Step 9: Try compiling a graphics.h program in C or C++, still there will be an error.步骤 9:尝试用 C 或 C++ 编译 graphics.h 程序,仍然会出现错误。 To solve it, open graphics.h file (pasted in include folder in step 3) with Notepad++.要解决此问题,请使用 Notepad++ 打开 graphics.h 文件(在步骤 3 中粘贴在包含文件夹中)。 Go to line number 302, and replace that line with this line : int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,转到第 302 行,并将该行替换为以下行: int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,

Step 10: Save the file.第十步:保存文件。 Done!完毕!

Note :笔记 :

Now, you can compile any C or C++ program containing graphics.h header file.现在,您可以编译任何包含 graphics.h 头文件的 C 或 C++ 程序。 If you compile C codes, you'll still get an error saying: “fatal error: sstream : no such file directory”.如果你编译 C 代码,你仍然会得到一个错误提示:“fatal error: sstream : no such file directory”。

For those who are still getting error (linker error) after following the above solutions.对于遵循上述解决方案后仍然出现错误(链接器错误)的人。
The build of the library at http://winbgim.codecutter.org/ is old and was last built around 2006.While linking against that using 64 bit toolchain results into linking error. http://winbgim.codecutter.org/上的库的构建是旧的,最后一次构建是在 2006 年左右。使用 64 位工具链进行链接时会导致链接错误。 Here is a recent build of the library bringing 64 bit compatibility.是该库的最新版本,具有 64 位兼容性。
Some win32 system call has also been updated to recommended 64 bit alternates to make it work.一些 win32 系统调用也已更新为推荐的 64 位替代品以使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM