how to include graphics.h in CodeBlocks?

graphics in codeblocks

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…

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 Code::Blocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> 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 CodeBlocks installed in C drive of your computer, go through: Disk C >> Program Files >> CodeBlocks >> 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.

compiler settings

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,

graphics in codeblocks3

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.]

2 thoughts on “how to include graphics.h in CodeBlocks?”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.