Generally you don’t need to install compiler separately in CodeBlocks since it also comes with compiler already included. But the problem is newer version of CodeBlock have problem if we try to add Borland Graphics Interface (WinBGIm) support, which allows to run graphics in C++ program. So here is how you can make include<graphics.h> work again in your CodeBlocks.
- Download CodeBlocks (codeblocks-20.03-setup.exe) without MinGW’s GNU GCC compiler, a separate TDM-GCC compiler and WinBGIm binaries from the download section below.
- If you had already installed CodeBlocks (codeblocks-20.03mingw-setup.exe) that comes with compiler then I recommend to uninstall it.
- Install TDM-GCC compiler while installing you need to select MinGW/TDM(32 bit) and make sure add to path option is selected. It makes CodeBlocks auto detect compiler.
- Install CodeBlocks (codeblocks-20.03-setup.exe). When you open CodeBlock it will auto detect compiler. CodeBlocks caches previous compiler settings so to make sure compiler settings are working go to Settings>Compiler then reset defaults. Now it will detect TDM-GCC as default compiler if not detected already.
- Now its time to place downloaded binaries to correct location. Copy the files inside lib (
libbgi.a) and include (
winbgim.h) folder to respective folder of TDM-GCC compiler
- Now in CodeBlocks inside Settings>Compiler>Linker settings, add
libbgi.ain Link Libraries: and put
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32in Other linker options:
- Save the settings and you are ready to run your graphics program in CodeBlocks.
- Check these images below to make sure you haven’t done any mistake.
In case you want to compile your own binaries
This is completely optional, it only describes how to compile your own binaries but I had provided you pre-compiled binaries. So need to worry about it. I have tried with the binaries and source provided at WinBGIm – Borland BGI Graphics Emulation but it was not working. A working source code of WinBGIm and instruction to compile binaries are available here.
- WinBGIm Binaries – https://drive.google.com/open?id=1joDbQBIsnjCElEpUx4z59oWbiXcwACha
- CodeBlocks – http://www.codeblocks.org/downloads/26 (remember to download codeblocks-20.03-setup.exe)
- TDM-GCC – https://jmeubank.github.io/tdm-gcc/download/