添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams graphics.h isn't a c++ standard header. What toolchain are you using? IIRC the only one supporting that out of the box is the ancient Turbo C++ compiler. πάντα ῥεῖ Dec 10, 2016 at 9:23

Step 1: Download graphics.h library from http://winbgim.codecutter.org/ or use this link .

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. (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.)

Step 4: Copy and paste libbgi.a to the lib folder of your compiler directory.

Step 5: Open Code::Blocks. Go to 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.

Step 7: Go to “Other linker options” on the right part and paste these commands:

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

Step 8: Make sure you got steps 6 and 7 right! 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. To solve it, open graphics.h file (pasted in include folder in step 3) with text editor. 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"

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.h header file. If you compile C codes, you’ll still get an error saying: “fatal error: sstream : no such file directory”. For this issue, if your file extension is .c, change it to .cpp.

Using the angle brackets "<>" assumes graphics.h is part of the C standard library. 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.

In your source code, you will then write: #include "graphics.h"

paste the graphics.h and winbgim.h into C:\MinGW\include folder. Then paste libbgi.a to C:\MinGW\lib. this solution will be worked. because your default compile's installation location set to C:\MinGW. otherwise you can change your compile's installation location in 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?

Step 1: To setup “graphics.h” in CodeBlocks, first set up winBGIm graphics library. Download WinBGIm from Borland BGI emulation for MingW.

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. (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.)

Step 4: Copy and paste libbgi.a to the lib folder of compiler directory.

Step 5: Open Code::Blocks. Go to

Settings >> Compiler >> Linker settings

Step 6: In that window, click the Add button under the “Link libraries” part, and browse.

Select the libbgi.a file copied to the lib folder in step 4.

Step 7: In right part (ie. other linker options) paste commands

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

Step 8: Click Ok

Step 9: Try compiling a graphics.h program in C or C++, still there will be an error. To solve it, open graphics.h file (pasted in include folder in step 3) with Notepad++. 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,

Step 10: Save the file. Done!

Note :

Now, you can compile any C or C++ program containing graphics.h header file. If you compile C codes, you’ll still get an error saying: “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. Here is a recent build of the library bringing 64 bit compatibility.
Some win32 system call has also been updated to recommended 64 bit alternates to make it work.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.