Getting graphics.h to work on mingw32 gnu C++ compiler

Posted on January 22, 2011

23


Some schools and colleges still use the old Turbo C++ IDE (with compiler) for C/C++ programming. It does not seem surprising. But problems arise if the student has a modern PC running 64-bit(x64) windows operating system. The OS simply refuses to run old 16-bit dos programs (one of them being Turbo C++ IDE whose product line was put on hold after 1994).

Since the Turbo C++ IDE cannot be run on 64-bit(x64) windows OS, the user may choose to use a modern IDE like Microsoft Visual C++, Netbeans (Yes, even for C/C++), Bloodshed Dev C++ (outdated), Eclipse or Codeblocks. However, the problem is still not solved. The header graphics.h and its library are not available with other compilers (not even Borland 5.5). For the purpose of compatibility, a free utility called WinBGIm is available. Follow these steps to get graphics.h working with mingw32 gnu C++ compiler (which is very popular).

  1. Get an IDE. Some of them are mentioned above. (I use Codeblocks, Netbeans as examples here).
  2. Get mingw32 GNU C++ compiler from here. OR it is optionally available with Codeblocks IDE here (be sure to check whether the file has mingw in it).
  3. Install the compiler and the IDE (in this order). Configure your IDE to work with the mingw GNU C++ compiler. Codeblocks if downloaded with mingw automatically sets it as default so that Codeblocks users just have to download and install the setup file. If you use Netbeans (with C/C++ plugin), go to Tools menu > Options > C/C++. Click on Add and paste the address of the bin folder of your compiler (in my case it was C:\MinGW\bin). Additionally you need to install MSYS for netbeans from here. Version 1.0.11 is enough. Configuration is explained in the netbeans community release.
  4. Download WinBGIm and extract the files.
  5. Copy the header files (with extension .h) in WinBGIm to the include directory of your compiler. In my case it was C:\MinGW\include.
  6. Copy the library files in WinBGIm (with extensions like .a, .o) to the lib directory of your compiler. In my case it was C:\MinGW\lib.
  7. If your IDE can add link libraries (like Codeblocks, Netbeans), add these files which are found in the lib directory mentioned in step 6 to your linker libraries (in same order) :
    libbgi, libgdi32, libcomdlg32, libuuid, liboleaut32, libole32. If they are not found, try l instead of lib (it is the letter ‘l’ not one). For Codeblocks, use Project menu > Build Options > Linker Settings tab > Add to add each library one by one. For Netbeans (right click on Project) > Properties > Linker > Libraries entry > …(button) and add the above libraries. If your IDE does not support that, you can add these to your linker command (try the l letter instead of lib if it does not work) -libbgi -libgdi32 -libcomdlg32 -libuuid -liboleaut32 -libole32. An example of a command : g++ bgidemo0.cpp -libbgi -libgdi32 -libcomdlg32 -libuuid -liboleaut32 -libole32 -o bgidemo0.exe
  8. Write and execute the program as you normally would, including graphics.h header file in your program.
About these ads
Posted in: Netbeans