How to setup winBGIm library in CodeBlocks

How to setup winBGIm / graphics library in Code Blocks

Note: I have answered few FAQs in the Internet regarding this topic at the very end of this blog. Go through those if you have already tried main explanation.


Things everybody skip: Those who think, TurboC is too old to use these days and wanna upgrade to other cool compilers like, Microsoft Visual Studio(best one so far), Code::Blocks, Dev C++ or any other. It's a good thing to do.

I have used MicroSoft Visual Studio, Code::Blocks and Dev C++ for few years now and I find Code::Blocks to be the better one next to Visual Studio. Dev C++ is good in some ways but Code::Blocks gets better and better with each updates. So, I recommend Code::Blocks over Dev C++.

Alright, let's get to the point, I was trying few graphic coding the other day in TC(Yeah, I still use it sometimes; Because, it's kinda home for us, 90's kids) because I was bored to configure Code::Blocks to graphics. Until now. So , I started my journey to find 'ways' to setup graphic coding in code::blocks. It took few hours. It was pain in the ass. I am writing this blog to save that pain for ya! Hey, Imma good guy, alright!

I think, there are three kinds of people in this world:
* Those who program.
* Those who try/tried programming and
* Lame.

Alright, let's get to the point.. really..

Now, those who are trying to use graphics.h in Code::Blocks, ATTENTION!

So, how to include graphics.h in Code::Blocks? If you've tried downloading graphics.h header file and pasting it in the include directory, but yet it's showed/showing error, blablabla... here's a step-by-step solution! You know it or not, there are few settings Code::Blocks wants you to make, to successfully run or execute C/C++ graphic programs.

Stuff to read: To setup graphics in Code::Blocks, you'll first have to set up winBGIm library(download graphics.h). WinBGIm is a graphics library ported to computer by Michael Main(Thanks man!) at the University of Colorado(I hope, I spelled it correctly). It emulates graphics for the MingW(GCC port) compiler. Like the TC++ IDE, the BGI(Borland Graphics Interface), is old; But not outdated, yet. It is still used in many C/C++ programs in schools and colleges.

Hmm, even though you can find many alternatives to winBGIm library, it is good for beginners in programming field. WinBGIm is the easiest graphic library you can find-Yeah!


Steps to include graphics.h in Code::Blocks:
Note: Last step is very important.

Step 1: Download of Code::Blocks v16(latest) and install it. This step is NOT necessary. It's just good thing to be up to date to avoid bugs. You can skip this step, if you are fine with whatever version you have. LINK. Size: 78.6MB

Step 2: Now, download winBGIm.rar(It's actually same link as above). Size: 24KB
Note: That link also contains Test codes, so that you can test whether your setup is working or not. And also, ScreenShots of settings to make inside CodeBlocks.

Step 3: Extract(of course) and you'll get these files:
  • graphics.h
  • winbgim.h
  • linker_code.txt
  • libbgi.a

Step 4: 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:
Drive C > Program files or Program files(x86) > CodeBlocks > MinGW > include

Step 5: Copy and paste libbgi.a to the lib folder of your compiler directory. Same path as above.

Step 6: Now, open Code::Blocks. Go to Settings > Compiler > Linker settings

Step 7: 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 5.



Step 8: Go to "Other linker option" on the right part of same window and paste these commands or use linker_code.txt file:
    -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32



Step 9: Make sure you got Steps 7 and 8 right!

Step 10: Say out loud: Yay! We did it!


Edit: I have deleted old comments and answered common questions below in FAQ section. If you have any questions, bring them up in the comments section. Also, now that the post is revised and updated, leave a feedback in the comments, if the aforementioned procedure to include graphics.h in CodeBlocks worked out for you.
___________________________________________________________________________________


Here are some frequently asked questions answered:

Question 1: Hey Tejas, I have completed all above steps carefully but I am still getting following error while building program with graphics.h header:
fatal error: sstream : no such file directory
What should I do now?
Answer: This is probably because you have file extension .c; Change it to .cpp
Reason is, there is no library sstream in C. It's in CPP. Since graphics.h uses sstream, you have to code all graphic programs with .cpp extension. No big deal. Cheers!


Question 2: Some people in Internet suggested me to edit graphics.h's 302nd line from int right=0 to int top=0; But still I have errors. What to do?
Answer: This is probably because, you are using 'bad' library files. Go to Step 3 and download 'bug fixed' library files. Replace previous files with new(downloded) ones following above steps. You don't have to link again, though. Just check commands in Step 8 once. And you can celebrate! 


Question 3: Thanks for the detailed tutorial. After doing all the necessary steps, my program builds without error. But, when I run it, my console window crashes with error 
filename.exe has stopped working.
Also message displayed is process returned (0xFF). Kindly help me with what could be the reason of this.
Answer: You're welcome. Again this is because of 'bad' library files. Note that, process is returning a very big number. So, this is runtime error. Refer to Question#2 and it's answer.



Comments

  1. Thank you so much! I did everything from extracting the file, changing the code at 302th line to setting up the ideal linker settings. But it did not helped me and I didn't know why, but after downloading file from here everything went smooth. Programs are successfully running. I feel glad that I read this here. I am still getting the warning but programs are running without any problems.

    ReplyDelete
  2. thank uh so much ,that really works

    ReplyDelete
  3. Change the main file extension to .cpp ? That doesn't work either

    ReplyDelete
  4. Thank you very much for taking the time to write this post, it really is very helpful. Greetings from Mexico.

    ReplyDelete
  5. I am still not getting the output. After doing these all steps .
    The error is :
    Process returned -1073741819 (0xC0000005) execution time : 4.094 s
    Press any key to continue.

    please help!

    ReplyDelete
    Replies
    1. just download above files and replace them in MinGW folder

      Delete
  6. Thank you so much for those bug free Winbgim files.
    Files from the WinBgim website had some problems and i was getting 0xC0000005 error.

    ReplyDelete
  7. does not work . LInking error : cannot find -lbgi

    ReplyDelete
  8. how to download 'bug fixed' library files?

    ReplyDelete
  9. I'm still getting "Process returned -1073741819 (0xC0000005) execution time : 1.115 s" after meticulously following all of your steps :/

    ReplyDelete

Post a Comment

Leave your comment here

Popular posts from this blog

The Chapter x

Random thoughts.