C language, Programming

Updated on:

C language, Programming

Updated on:

How to add graphics in dev C++

Dev c++ needs graphics.h header file to provide graphics capability to computers. Graphics is outdated and like from 20+ years ago. Modern 64-bit computers do not support it anymore.

During the MS-DOS era, it was popular and utilized by many programs. Although, whoever is new to graphics can still learn a lot about graphics.h library and build the basic foundation of modern graphics.

There are more complicated but better libraries than graphics.h. To name a few –

  • OpenGL
  • DirectX
  • SDL
  • SFML
  • Allegro

If you are struggling to configure graphics in dev C++, this tutorial will explain step by step how to add graphics in dev C++.

How to add graphics in dev C++ (follow these steps)

Step 1: Download/update the latest version of dev C++

It’s a good idea to have the latest version of the Dev C++ application. With the updated version, you will likely receive new features, fewer bugs, and security patches.

Go ahead and download the latest build of dev C++. I’m using version 5.11 while creating this article. You might get an upgrade, but the procedure remains the same. You can check your dev c++ version by selecting “help” from the top menu and selecting “About Dev C++.”

dev-c-version

Step 2: Add header source files into the Dev C++ directory

Next, you need to download graphics library files and add them to the appropriate folders under the MinGW64 directory. Follow this –

  1. First, download the header files from this Google drive link and extract the files.
  2. It contains three files – graphics.h, winbgim.h and libbgi.a.
  3. You need to copy “graphics.h” and “winbgim.h” into include the directory of Dev-Cpp program resource files. The exact directory address is –
    • C:\Program Files (x86)\Dev-Cpp\MinGW64\include
  4. Next, copy “libbgi.a” to lib folder, which should be inside MinGW64. The directory address is –
    • C:\Program Files (x86)\Dev-Cpp\MinGW64\lib

Double-check the include and lib folders have these files to proceed to the next step.

How to add graphics in dev C++

Step 3: Change compiler suit in Dev C++

Compiler suites combine the latest stable release of the GCC toolset and open-source MinGW runtime APIs to build an open-source alternative to Microsoft’s compiler. You must set the TDM – GCC version to the 4.9.2 32-bit release.

  1. First open Dev C++ appliaction.
  2. On the right side of the toolbar, you will have the drop-down menu to select the desired compiler suit.
  3. Set it to TDM - GCC 4.9.2 32-bit release.
TDM-GCC-configuration
Tutorial: How to add graphics in dev C++

Step 4: Configure required linkers for graphics

Configuring linkers is vital; this program will help link a program’s object modules into a single object file. For graphics.h setup, you will need these linkers to be set for the selected compiler suite, aka TDM - GCC 4.9.2 32-bit release.

Steps to configure graphics.h linkers:

  1. On Dev, C++, look for the Tool option on the top menu.
  2. Expand tools and select Compiler Options.
  3. You should arrive on the general tab of the compiler options window.
  4. Ensure the “Add the following commands when calling the linker” check box is selected.
  5. Then add these linkers in the input box – (just copy and paste this line)
    • -libgcc -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  6. Then click on OK to save.
Compiler-options-linkers-for-graphics.h

When complete, you are ready to use graphics.h header in your c or c++ programs.

Step 5: Verify whether graphics.h header is working (optional)

Create a new source file and write a program to test graphics.h header. You can try it with anything you want; for example, I’m trying to print GANA (in the Hindi language) using basic graphics output primitives…

#include<stdio.h>  
#include<conio.h>  
#include<graphics.h>  
#include<dos.h>  
main()  
{     
    int gd=DETECT,gm;  
    initgraph(&gd,&gm,"c:\\tc\\bgi");  
    setbkcolor(9);  
    line(130,100,290,100);  
      
    line(165,100,165,155);  
    arc(150,155,100,0,15);  
    line(180,100,180,170);
	line(190,100,190,170);  
  
    circle(220,140,10);  
    line(220,130,255,130);  
    line(255,100,255,170);  
    line(265,100,265,170);  

    getch();  
}

And here’s the output:

print-gana-in-hindi-using-graphics-in-c

Still unable to add graphics in Dev C++?

Eventually, this guide should get your graphics.h header to work with the Dev C++ application. If you haven’t followed the process thoroughly to avoid skipping steps… or if that’s not the case, then probably uninstall any previous version of Dev C++ and have the latest build. Then follow these steps again.

📝 Similar Articles:

  1. How to fix this person is unavailable on messenger issue
  2. 6 ways to create professional videos using an online video editor
  3. Instagram saved posts not loading – how to solve?
  4. How to Download Apps on Vizio Smart TV
Photo of author

Rupam Bharali

Hey there, I'm Rupam. I like gaming, exploring gadgets & software, watching TV shows and other people's streams. I created this website to share my thoughts on people's queries regarding software-related issues, guides, streaming, gaming, and PCs. I hope you find my content helpful. Feel free to take a glance and share your thoughts with me.