Sunday 6 September 2015

Running Graphics Program of C on Windows 7 64 bits In CodeBlocks IDE 13.12


Today we are going to see how to run C graphics program on 64 bits Windows 7 using CodeBlocks 13.12. 

It will require only 12 steps. Follow with caution and you are done.

These are the instructions I have tried for 64 bits windows 7:
  1. Download zip file from this repository: https://github.com/stahta01/windows-games
    This one is having latest files of Graphics Libraries.

  2. Now either you are using external GCC compiler or internal GCC compiler doesn’t matter, just follow the universal procedure recommended for this.
  3. Copy the following files 
From(windows-games-master\WinBGIm)
To (MinGW)
include folder  => graphics.h
Include
src folder => Winbgim.h
Include
lib folder => libbgi.a
Lib

           If any of the files are already at destination, please overwrite as these are going to work for 64
           bits versions.

4.  Now, go to Setting => Compile and Debugger => Selected Compiler => GNU GCC Compiler.
           -  I will recommend to make copy of existing compiler and rename it. So that any kind of mess will not
           disturb other type of program execution. 



     5.    Now in Linker settings => Add => File => C:\MinGW32\lib\libbgi.a
      
     6.    Go to right part, other settings paste these parameters:
           -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
       
     7. Now half of the configuration has been done.

          
     8. Create simple empty project using codeblocks and add file with extension .cpp.
  
     9.     Most IMPORTANT part is now:

      
Now, right click on Project Name => Build Options => selected Compiler.

       You have to select the compiler which you have configured.
       Otherwise you will get:
       i. Memory access violation error "Process-returned-1073741819-0xc0000005" 
               or 
      ii. Segmentation fault.
  
     After successfully completing above steps, try the following program with Hello.cpp   
  
     This is my sample program to print name of screen:

 #include<graphics.h>  
 #include<conio.h>  
 main()  
 {  
   int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;  
   initgraph(&gd, &gm, "C:\\TC\\BGI");  
   rectangle(left, top, right, bottom);  
   circle(x, y, radius);  
   bar(left + 300, top, right + 300, bottom);  
   line(left - 10, top + 150, left + 410, top + 150);  
   ellipse(x, y + 200, 0, 360, 100, 50);  
   outtextxy(left + 100, top + 325, "My First C Graphics Program");  
   getch();  
   closegraph();  
   return 0;  
 }  


    10.  Now, rebuild the project.

    11.  After that, compile and run.

    12.  You will definitely see such message printed,



7 comments:

  1. Howdy --
    I'm attempting to find libbgi.a in your windows-games, and don't see it. Could you point me towards this?
    Many thanks,
    David Small

    ReplyDelete
    Replies
    1. Download this file it is having libbgi.a

      http://winbgim.codecutter.org/V6_0/WinBGIm_Library6_0_Nov2005.zip

      Delete
    2. these files don't work

      Delete
  2. i followed your steps carefully, but when i run the program, it stops working.. A pop up window by Windows OS comes and "says "myprogram.exe" has stopped working. Windows is finding a solution for this"....

    ReplyDelete
  3. there is no lib folder . So no file named libbgi.a in the zip.

    ReplyDelete
  4. thanks, this way c gets compiled well with codeblock and when i run the compiled exe file my 64bit window 8.1 shows error message and shuts down it.

    ReplyDelete
    Replies
    1. I have the same error on a Win 7 64bit system.

      Delete