VOOZH about

URL: https://www.geeksforgeeks.org/cpp/include-graphics-h-codeblocks/

โ‡ฑ How to include graphics.h in CodeBlocks? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to include graphics.h in CodeBlocks?

Last Updated : 28 Jun, 2022

Compiling graphics codes on CodeBlocks IDE shows an error: โ€œCannot find graphics.hโ€. This is because graphics.h runs is not available in the library folder of CodeBlocks. To successfully compile graphics code on CodeBlocks, setup winBGIm library. 

 

How to include graphics.h in CodeBlocks ?

Please follow below steps in sequence to include "graphics.h" in CodeBlocks to successfully compile graphics code on Codeblocks. 
Step 1 : To setup "graphics.h" in CodeBlocks, first set up winBGIm graphics library. Download WinBGIm from http://winbgim.codecutter.org/ or use this link

UPDATE: 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 compiler toolchain it results into linking error. Here at https://github.com/ahmedshakill/WinBGIm-64 is a recent build of the library bringing 64 bit compatibility. Some win32 system calls have also been updated to MSDN recommended 64 bit alternates for preciseness.


Step 2 : Extract the downloaded file. There will be three files: 

 

  • graphics.h


 

  • winbgim.h


 

  • libbgi.a


 

๐Ÿ‘ Image



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

๐Ÿ‘ Image




 

๐Ÿ‘ Image



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

๐Ÿ‘ Image



Step 5 : Open Code::Blocks. Go to Settings >> Compiler >> Linker settings. 
 

๐Ÿ‘ Image




 

๐Ÿ‘ Image



Step 6 : In that window, click the Add button under the โ€œLink librariesโ€ part, and browse. 
 

๐Ÿ‘ Image


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

 

๐Ÿ‘ Image



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


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

 

๐Ÿ‘ Image



Step 8 : Click Ok 
 

๐Ÿ‘ Image



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, 
 

๐Ÿ‘ Image



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โ€. 
 

๐Ÿ‘ Image


 

For this issue, change your file extension to .cpp if it is .c
































 

Comment
Article Tags: