Code::Blocks is mostly used opensource IDE due its great features. However it can’t run graphics programs unless you include graphics.h. But we can make it work by adding WinBGIm graphics library manually. That way we can use #include<graphics.h> in Code::Blocls.
Code::Blocks is lightweight and easy to use and becoming opensource it is available for Windows, Linux and Mac and is free to download and use. It is best IDE for beginners who wants to learn and C, C++ and FORTRAN or for creating small projects. With addition of WinBGIm in Code::Blocks we can use graphics.h header file then compile and run graphics program in C++ without any errors. Let’s see how to include graphics.h in Code::Blocks.
How to add graphics.h support in Code::Blocks?
- Download WinBGIm from the download section below. Downloading from other website may not work since official graphics.h has minor error.
- Extract it.
- Open info.txt for linker options and more information.
- Copying MinGW folder to your Code::Blocks installation directory. Default Code::Blocks installation directory is
C:\Program Files (x86)\CodeBlocks. There will be MinGW folder already. Copying new MinGW folder only adds some library (
libbgi.a) and header (
graphics.h) files in that directory. To manually add files, copy
winbgim.hfiles in include folder of your compiler directory which is
C:\Program Files (x86)\CodeBlocks\MInGW. And copy
libbgi.ato lib folder of your compiler directory.
- Open Code::Blocks. In open Settings >> Compiler >>Linker Settings. Click Add button in link libraries part and browse and select
libbgi.afile you just copied to MinGW folder.
- In right part (i.e. other linker options) paste commands
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- Click OK.
If you didn’t see MinGW folder then it might be installed in different location. Check in C:\MinGW.
You can also watch my short video about adding graphics.h support in Code::Blocks
Now you can run graphics program in Code::Blocks by including graphics.h header. I have added a sample program clock.cpp with that WinBGIm archive file, you can try compiling it.
Note: If you are getting sstream not found error, then you probably trying to run a .c file program. sstream is c++ header so graphics.h won’t works with c.
You may also like How To Install Dark Themes In CodeBlocks?
Download WinBGIm graphics.h library
You can download corrected graphics library files from here – https://drive.google.com/open?id=1joDbQBIsnjCElEpUx4z59oWbiXcwACha
Here is the official link for WinBGIm graphics library – http://www.codecutter.net/tools/winbgim/ but it has small problem with graphics.h file which is have corrected. Line 302 has been replaced by
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,.