CodeBlocks IDE throws the error “Cannot find graphics.h” while attempting to compile graphics code. This is due to the fact that CodeBlocks does not have graphics.h in its library folder. Compiling graphics code on CodeBlocks requires the installation of the winBGIm library.
How to include graphics.h in CodeBlocks ?
To properly build graphics code on Codeblocks, please follow the steps in the order provided below to include “graphics.h” in CodeBlocks.
Step 1: First, the winBGIm graphics library must be installed for “graphics.h” to be used in CodeBlocks. Download the zip folder, the link is given below.
Step 2: Extract the downloaded file. There will be three files:
- graphics.h
- winbgim.h
- 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 the right part (ie. other linker options) paste the commands given below
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Step 8: Click Ok.

Step 9: Try compiling a graphics.h program in C or C++. You can use the given code below:
#include<graphics.h> #include<conio.h> int main() { int gd=DETECT, gm; initgraph(&gd, &gm, ""); for(int i=200;i<400;i=i+25){ for(int j=200;j<400;j=j+25){ circle(i, j, 100); } } getch(); closegraph(); return 0; }

If your problem is not solved, then kindly follow the below steps. It will surely solve your problem.
How to include graphics.h in CodeBlocks using TDM GCC?
If you are still facing the error thats mean you are facing compatibility issue. Your computer is running on 64 bit but CodeBlocks compiler is running on 32 bit. For this you have to download a software called “TDM GCC”. You can download it from here.
Make sure to download the shown version.

After Installing the software simply follow the shown order.
Step 1: Copy and paste graphics.h and winbgim.h files into the include folder of TDM GCC. (If you have TDM GCC installed in C drive of your computer, go through: Disk C >>TDM-GCC-32 >> include. Paste these two files there.)


Step 2: Copy and paste libbgi.a to the lib folder of compiler directory. (C >>TDM-GCC-32 >> lib)

Step 3: Now you have to again open the Compiler Settings and go to the Linker Settings. And edit the Link Libraries to change the libbgi.a file location.

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

Step 4: Now we have to change the Compilers directory and set it to TDM GCC.

Select the TDM-GCC-32 folder only. ((C >>TDM-GCC-32)

Step 5: Now you can run the code again and it may show output like below.

We really hope that this post helps you address the issue you were having with the graphics header file in the C programming language as well as the C++ programming language.