In my previous video, many of you have commented
that you guys are facing some error when you are set up "graphics.h" in CodeBlocks 20.03..
which is currently the latest version of CodeBlocks. So I decided to create
this separate video on this issue. Hey guys, My name is Ramesh and you are watching CodeWar.. So , in this video I will explain
How to setup “graphics.h” in CodeBlocks 20.03 and this will work for any new
version of CodeBlocks which will come later. So let’s begin. Okay, so here I am assuming that
you have installed CodeBlocks 20.03 along with the Compiler provided with it and you
have already tried to setup “graphics.h” using my previous video. But you are facing this error.
By the way if you are new to my channel and this is the first time you are trying
to setup “graphics.h” in CodeBlocks then you can skip this part. Now let me
explain first why are you facing this error message "fatal error: graphics.h: No such file or directory".. Actually in our case, the problem is related to Compiler compatibility.. Let me explain this with a short example.. Okay, before running this program, I will have
to remove flags from other linker options.. So, if you run this program, you
will get an output like this.. Here you can notice this line
"Target: x86_64-w64-mingw32".. If you are also getting similar output then it
means you have 64bit Compiler and this is actually creating the problem..
The graphics library we have is compatible with 32bit compiler but here we have 64bit Compiler, Right..? So when we are trying to compiling our program, the compiler
is trying to generate 64bit output and as we have 32bit version of graphics library, the Compiler
is simply ignoring "graphics.h" header file and that is why we are getting this error.. So,
to solve this problem, we can do one thing.. First we will setup 32bit compiler in CodeBlock and then
we will setup "graphics.h" in it.. So lets start.. So, first of all, you will have to download
this 32bit Compiler from this website.. I have mentioned link in the description
of this video. So visit to this site and download this 32bit compiler..
So, after downloading, we will have to install it.. So double click on this file to
start installation.. Now uncheck this "Check for updates" option and
click on "Create".. Click on Next.. and Install.. This will take some time so just wait for it to complete.. Okay, so our Compiler is installed successfully.. Click on Next and Finish.. Now we have to copy graphics library in our compiler.. You can download it from my google drive. I have
mentioned link in the description of this video. Okay, after downloading, you will get a zip
file like this.. Now extract this zip file.. Now select "graphics.h"
and "winbgim.h".. Copy it.. Now you have to go to the "include" folder
of the compiler.. So go to this location.. "C:\TDM-GCC-32\include".. Now paste it here.. In the folder where you extracted the zip
file, there is a file with name "libbgi.a".. Copy is and paste it to the
lib folder of your compiler.. You can see the location.. inside
"C:\TDM-GCC-32\" there is a "lib" folder, you have to paste it here.. So we are done with
files and now we have to configure our 32bit compiler with CodeBlocks and add the appropriate
linker options.. Now open CodeBlocks.. In the menu bar, go to Settings.. Compiler..
Go to this "Toolchain executables".. Now here you have to select the directory
or our new 32bit compiler.. So click on this browse button.. Now go to C drive and select this
"TDM-GCC-32" folder.. Now click on "Select Folder".. now go to "linker settings" and in the
"Other linker options", write this flags.. -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 Now click on "OK"..
So, we have set "graphics.h" in CodeBlocks.. Now lets create a new project and check
whether it is working properly or not.. Create a new project.. Select "Console
Application" and click on "Go".. Click "Next".. Now as I have already explained in my previous
video, if you want to write graphics program then always select C++ as your language..
So, select C++ and click on "Next".. Enter your project title.. Now browse to select a location
where you want your project to be created.. I am selecting "Desktop" here..
Click on Next and Finish.. Now lets write a short program using "graphics.h".. Okay, so the program is complete.. Now
click on this "Build and run" button or simply press the "F9" key.. You can see, it is working properly..
So guys, that's all for now.. Thanks for watching.. See you in the next video..