Adding graphics.h support in CodeBlocks with TDM-GCC C++ Compiler

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 (graphics.h & winbgim.h) folder to respective folder of TDM-GCC compiler C:\TDM-GCC-32\lib & C:\TDM-GCC-32\include.
  • Now in CodeBlocks inside Settings>Compiler>Linker settings, add libbgi.a in Link Libraries: and put -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 in 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.

Download section

9 thoughts on “Adding graphics.h support in CodeBlocks with TDM-GCC C++ Compiler”

  1. Perform my mentioned procedure and it generates this error
    ld.exe||cannot find -lbgi|
    I would appreciate if you can help me

  2. hi
    i could not find your email address so i will ask my question here..
    is there a trick or way to get the results of an C program into console..like matlab or python when you are doing numerical stuff you need to save the results..so i want this feature …also i’m using codeblocks…
    thank in advance..

    1. Is there any way that would work for 64-bit programms? This is why I downloaded codeblocks 20.03, for the 64-bit complier. If there is no waty to compile 64-bit executables with graphics.h then I can rollback to 17.12

      1. I think you did’t get this. Here we don’t use compiler that comes with CodeBlock. We download compiler separately and add WinBGIm library there. So There is no problem to use latest CodeBocks. TDM-GCC compiler that use also comes as 64 bit so you can try these binary I provided. If these binary does not work compile your binary from source and it will going to work.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top