How to Include graphics.h in Code::Blocks?

| |

Most of us learning Computer graphics want to get rid of weird looking and boring Turbo. ” Turbo C++ is a discontinued C++ compiler and integrated development environment originally from Borland. “, it is the first line about Turbo C++ in Wikipedia. Code::Blocks can be a better alternative to Turbo C++ for Computer graphics codes in C++.

According to Wikipedia,

Code::Blocks is a free, open-source cross-platform IDE that supports multiple compilers including GCC, Clang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins.

So how to compile graphics code in Codeblocks? It usually shows an error, “Cannot find graphics.h”. This error message is because you don’t have graphics.h header in the library folder of Code::Blocks. BGI(Borland Graphics Interface) is a graphics library for rendering in the DOS platform. So with Windows we have WinBgi which is a Borland emulation for MingW.

How to Include graphics.h in Code::Blocks?

Before proceeding, you need to download the libraries from the link below: Download Here

If the above button doesn’t work, copy and paste the below link in the browser.

(You can also find the library in official website but installing those files will end up with some errors so we have provided Google drive link of error free library files)

Step 1: Extract the files from the Zip that you downloaded from google drive. There are 3 files: 

  • graphics.h
  • winbgim.h
  • libbgi.a

Step 2: Copy and paste libbgi.a file to ”lib” folder inside the compiler directory.

(Find your Codeblocks installation directory first, there is MinGW folder inside which the lib folder lies. Mine is C:\Program Files (x86)\CodeBlocks\MinGW\lib )

Step 3: Copy other two files graphics.h and winbgim.h to “include ” folder inside the compiler directory.

Step 4: Open CodeBlocks and Go to Setting>>Compiler

Step 5: Click Linker Settings and click on ‘Add’ button below link libraries box .  

  Select libbgi.a file added in Step 2 (C:\Program Files (x86)\CodeBlocks\MinGW\lib\libbgi.a) and click ok.  

Step 6: Now paste the following commands in the right side box(Other linker options:) -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Click Ok button in  right bottom corner.   Great!! Now you are ready to run your graphics code using graphics.h library in CodeBlocks.
Did it work?? Feel free to comment below. ????


Flutter 1.17: first stable version for 2020 released along with Dart 2.8

Steve Jobs: a Self-made billionaire

Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments

||=== Build file: “no target” in “no project” (compiler: unknown) ===|
D:\bluetooth\Desktop\XX.cpp||In function ‘int main()’:|
D:\bluetooth\Desktop\XX.cpp|7|warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]|
\Program Files\CodeBlocks\MinGW\lib\libbgi.a||No such file or directory|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 4 second(s)) ===|

Compiler showing this thing.

Would love your thoughts, please comment.x