graphics.h is used for drawing graphics in c language. You can draw the different shapes, graphs, or write your name using this library in c language. This library is pretty cool. But questions come in our mind that how to include graphics.h library in our CodeBlocks software and can start drawing amazing graphics. So let’s move towards the answer on how to include graphics.h in CodeBlocks…
Note:
New Codeblocks version(20.03 or later) that comes with the MinGW compiler doesn’t work. If you have already installed codeblocks with the MinGW version then please uninstall it and reinstall the codeblocks setup and MinGW compiler separately. Here are the links for codeblocks and the MinGW.
Codeblocks:
http://www.codeblocks.org/downloads/26
(select only setup file, e.g. “codeblocks-20.03-setup.exe”)
MinGW:
https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe
(After Installation add the path to the Environment variable. The path will be “C:\MinGW\bin”)
step 1
Download WinBGIm 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 MinGW installed in C drive of your computer, go through
Disk C >> MinGW >> include
. Paste these two files there.)
step 4
Copy and paste
libbgi.a
to the
lib
folder of your compiler directory. (If you have MinGW installed in C drive of your computer, go through
Disk C >> MinGW >> lib
. Paste these one files there.)
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 the previous two steps. Then,
click Ok
.
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 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,
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.
[If still it is not giving an output then use this
link
and download ‘libbgi.zip’ file then extract it. you are getting “libbgi.a” file. Copy and paste libbgi.a to the lib folder of your compiler directory.(If you have CodeBlocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> MinGW >> lib. Paste these one files there.) now your program will work.]
Related
Era Innovator
Era Innovator
is a growing Technical Information Provider and a Web and App development company in India that offers clients ceaseless experience. Here you can find all the latest Tech related content which will help you in your daily needs.
Thanks for your tutorial. However, after replacing the stuff on line 302, I couldn’t save it. What’s up! Please help.
still showing the same error as “C:\Users\saini\Desktop\c++ programs\line.cpp|2|fatal error: graphics.h: No such file or directory|”
We have updated the article. It was very hard to find the solution, but our hard-working effort found the solution. The problem was with the latest codeblocks version (20.03) which comes with MinGW setup. So we tried installing codeblocks and MinGW separately and following same process described above and it worked. Now, if there is still any problem, then please tell us.
I did everything as directed but am still getting the error *fatal error: graphics.h: No such file or directory*
Please help…
We have updated the article. It was very hard to find the solution, but our hard working effort found the solution. The problem was with the latest codeblocks version (20.03) which comes with MinGW setup. So we tried installing codeblocks and MinGW separately and following same process described above and it worked. Now, if there is still any problem, then please tell us.
We have updated the article. It was very hard to find the solution, but our hard working effort found the solution. The problem was with the latest codeblocks version (20.03) which comes with MinGW setup. So we tried installing codeblocks and MinGW separately and following same process described above and it worked. Now, if there is still any problem, then please tell us.
We have updated the article. It was very hard to find the solution, but our hard working effort found the solution. The problem was with the latest codeblocks version (20.03) which comes with MinGW setup. So we tried installing codeblocks and MinGW separately and following same process described above and it worked. Now, if there is still any problem, then please tell us.
We have updated the article. It was very hard to find the solution, but our hard working effort found the solution. The problem was with the latest codeblocks version (20.03) which comes with MinGW setup. So we tried installing codeblocks and MinGW separately and following same process described above and it worked. Now, if there is still any problem, then please tell us.
Please, check again that which codeblocks version you are using. If you are using codeblocks 20.03, then check if you have codeblocks that comes with pre-installed MinGW. If you have that version then you have to uninstall it and install codeblocks and MinGW separately. And if you have other errors then please write the complete error in comment, so we can review and answer it.
Here is the link for downloads of Codeblocks & MinGW :
Codeblocks:
http://www.codeblocks.org/downloads/26
MinGW:
https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe
Please, state the errors clearly. You can write all the errors in comment, so that we can solve them step by step.
Process returned -1073741819.
I tried the example from:
https://www.cs.colorado.edu/~main/bgi/doc/initgraph.html
We have tried the example and found the error. The error was “fatal error: sstream: No such file or directory”. Actually whenever you find these kind of problem, just change the file extension to the “.cpp” because these file don’t exist in C. You have to use C++ or have to just change the extension to “.cpp” and it will work.
I followed all the steps , my code is executable yet when i execute it the BGI window doesn’t appear and im only shown this command :
Process returned -1073741819 (0xC0000005) execution time : 11.760 s
Press any key to continue.
I followed all the step, my code was compiled with no fatal errors but when i execute it , the BGI window doesn’t appear and i m only shown this following command:
Process returned -1073741819 (0xC0000005) execution time : 11.760 s
Press any key to continue.
And the program extension should be ‘.cpp’. If this simple program runs, that means that there may be some problem in your program. So try debugging your program or you can search google to get optimized code for the program.
Process returned -1073741819 (0xC0000005) execution time : 11.760 s
Press any key to continue.
same problem. I used your sample code.
Please try clearing system cache using any software like CCleaner and restarting your pc. Still if it doesn’t work, then try reinstalling both the Codeblocks and MinGW.
It worked for me after some time of trying. My pc works on a 64-bit system. Don’t know if this matters.
– first I deleted Codeblocks completely from my computer.
– I installed codeblocks-20.03-setup.exe from this site:
https://www.codeblocks.org/downloads/binaries/
– I followed instructions on how to connect MinGW to Codeblocks with this video:
https://www.youtube.com/watch?v=1Ru4jcTWmwk&ab_channel=StudyKorner
BUT I downloaded MinGW from this site:
https://sourceforge.net/projects/mingw/
– after you followed the steps in the video, I did the steps on this website
– now it should work including
Thank you so much ERAINNOVATOR.
This is working perfectly fine, I have tried on Windows 7 + Codeblocks 20.03 + mingw32 separately installed
Thanks for your time ,when I download and open the files I get graphics winbgim ans libbgi.a with not extension H .is this correct? thanks again ,,Victor
If you are getting
“fatal error: sstream : no such file directory”
error then, change your file extension to
.cpp
if it is
.c
-1073741819 (0xC0000005)
This is what is being returned and the console is not opening.
Device was restarted and everything said was done….
Still it is returning the same outpur as provided above.
After searching so many solution but not luck. But I found this and it is working great.
Thanks a lot.
I get an error saying
“cannot find -lbgi: No such file or directory
error : id 1 exit status”
Please help me, ty