CPP graphic.h in codeblock


I have included graphics.h in Codeblock and used initgraph() to rezise my console window. It can compile but it only outputs a default black window which return "Process returned -1073741819 (0xC0000005) execution time : 2.970 s Press any key to continue.."

#include <iostream>
#include <graphics.h>
using namespace std;

int main(){
asked on Stack Overflow Sep 8, 2020 by john

1 Answer



Abandon graphics.h and use a modern graphics library. graphics.h is the header for the Borland Graphics Interface (BGI), a library shipped with the Borland development tools of the 1980s and early 1990s and intended for use with the DOS operating systems. It is old. Use of it professionally is exceptionally rare, so there is minimal value in learning it when you could be learning a graphics library that is used professionally and supported by modern development environments and hardware. For example, the graphics tools built into SFML and SDL.

If this is for school and you must use an implementation of graphics.h to satisfy the marking criteria, either

  • Exactly duplicate the set-up used by the marker. This minimizes the risk of differences between your environment and the marker's resulting in a program the marker cannot mark. You may be able to make a virtual machine that emulates the the marker's environment.
  • Download, install, and configure a modern implementation of graphics.h like SDL_BGI (Source if you need to build it yourself). The risk here is you may write code and use functionality that is not available to the marker's environment or write code that behaves differently.

What's likely happening:

As I recall the implementation of graphics.h most commonly suggested online required GCC3.4, and the odds of you getting Code::Blocks with GCC less than 4.8 these days is astonishingly small. And even version 4.8 is horribly out of date. Mainstream GCC is on 10.2.

To add to the fun, the library will have been written to run on the then-flagship Windows XP operating system and the graphics cards available at the time. Both have changed dramatically since then. So even if you track down GCC 3.4, successfully install it, and configure Code::Blocks to use it, you may find yourself needing Windows XP and a vintage 2005 graphics card because there's no way Windows XP will have a driver for whatever graphics card you are using.

This means your code can be 100% correct but the library you are using simply does not run as expected with the tools you're using. Your only option is to use other tools or use a different graphics library.

answered on Stack Overflow Sep 8, 2020 by user4581301 • edited Sep 8, 2020 by user4581301

User contributions licensed under CC BY-SA 3.0