information."> Running Visual C++ programs in DevC++

How to Port Visual C++ Programs to DevC++

Author: Vivek Saxena <vivek at zephyrix dot tk>
Last Updated: Wednesday, June 15, 2005 12:26 IST

[Return to homepage ; programming page]


What is this page about?

This page is about porting a program originally meant for Visual C++ to Bloodshed DevC++. If you don't know, DevC++ is an excellent C/C++ compiler that has support for the Windows GDI, OpenGL, console and GUI apps, libraries, etc. It runs faster than Visual C++ on my Athlon XP 2000+ box (click here for specs) and has a lot of cool options. Get it from BloodshedSoftware (see [2]). using this link. Having successfully run dynamic 3-D rotation and translation OpenGL programs on both DevC++ and VC++, I have come to the conclusion that DevC++ is more efficient and reliable. The info on this page is geared more towards OpenGL programmers and so, the hype about GL, but you should be able to get just about any Win32 program written in Visual C++ to run under DevC++ in a matter of seconds.

I personally recommend the use of DevC++ everywhere, especially in graphics and Windows GDI programs. I am not very sure if DevC++ supports all GDI features, but it certainly has a plethora of its own and the compile time for a reasonably large program that initializes OpenGL, creates memory for a 256x256 bitmap (test conditions) and does controlled cube rotation and texture mapping (slightly similar in looks to NeHe's Tutorial 07). But the issue really isn't compile time for this program, but it is the integration of the Windows GDI (Microsoft aficionados--if there are any at all ;-), read this) with third-party compilers. A fair idea can be obtained by download any OpenGL 3D sourcecode file from nehe.gamedev.net  and compiling it under DevC++.

For the experienced programmers out there, DevC++ sourcecode is available in Delphi on BloodshedSoftware's website: www.bloodshed.net.

NOTE: I have not tested all Microsoft (or third-party programs/libraries meant for VC++) SDKs such as DirectX or Direct3D in DevC++ yet, so I cannot say how easy it is to port Microsoft stuff. This page is meant for people (like me) seeking alternatives to slow and inefficient compilers. DevC++ is the answer. Besides, it is free, you can do almost anything with it and it is fast and powerful (though smaller in file size in comparison with VC++).

The information on this page originated when I wanted to try out a different compiler to test older OpenGL programs with. For those of you who have read the SuperBible, you would be anxious to go beyond VC++. After all, MS didn't make OpenGL and so, even if you were to use their libraries, headers and implementations, you would still need a fast and efficient compiler that doesn't stand in the way of pure ASM and your HLL (high level language) code.


Getting things to run

A Visual C++ program consists of one or more sourcecode files, a local header file (sometimes, this is not present or needed), a resource file (containing information about the resources you have used--this can contain info about UIs as well) among other things such as object files and other compiler-generated files depending on the options specified.

The main component of any program/project in VC++ is the list of external library files and headers. The library list can be accessed by going to Project-->Settings-->Link in the Visual C++ IDE. The list of libraries that you need here is essentially the list of those files (.lib files) that are unique to your program. Supposing you made an OpenGL program, you would normally need files like OpenGL32.lib, GLu32.lib, GLaux.lib and maybe even glut32.lib. To port your OpenGL program in DevC++, you need to know the complete path of these libraries.

  1. Copy all unique library files (.lib) used by your program to $DEV_CPP_DIR\lib\.

  2. Though not required always, a set of preprocessor directives telling the compiler which lib files to use can be used. These have been found to work both with DevC++ and Visual C++. Insert the following lines just before the include directives (just before #include) in your main .cpp implementation file (main program code):

    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glaux.lib")


    You can replace the abovementioned library names with the ones you use.

  3. In DevC++, go to Project-->Project Options or press Alt+P. Under the General tab, add the following options in the input space below Linker Options/Optional Libs or Object files:

    -lglu32 -lopengl32 -lglut32 

              

  4. If you're not making an OpenGL project, replace the above line with a compatible option (visit [1]). If your option is not listed or you want to specify a particular library file, click on browse and select that file. It will be added to your project.

  5. Copy all external headers either to $DEV_CPP_DIR\include\ or to your project directory and specify their path. (Do not copy compiler specific headers--copy only those headers that are unique to your program. For OpenGL, copy the glaux.h and glut.h headers to $DEV_CPP_DIR\include\gl\).

Having completed all the five steps, compile your DevC++ program by pressing F9. If you've followed each step mentioned on this page, chances are high that your program will work. In case it doesn't work, or it gives errors, there is a higher likelihood of programming errors or setup errors with DevC++. Check your program first and copy the checked code from DevC++ to VC++ and compile it there. If it works in VC++ and not in DevC++, the problem could be due to one or more of the following possibilities.

  1. Your program code contains VC++ specific instructions.

  2. DevC++ isn't installed correctly on your system. Uninstall it and rerun the setup file, after deleting all traces of DevC++ from the installed folder and the registry. Use a regclean utility if possible.

  3. The libraries in use are VC++ specific and/or headers are VC++ specific.

  4. You haven't followed the abovementioned steps exactly.

$DEV_CPP_DIR is the default DevC++ installation directory (folder).

If you find any mistakes in this tutorial, let me know asap. Some useful information is also available in [1]. This info should be helpful for everyone. This tutorial was created for DevC++ 4.9.7.0 and Visual C++ 6.0.


References

[1] Bolin, Chuck. Programming in C++ for Free: www.clg-net.com/ai/cprogramming.htm


[2] BloodshedSoftware DevC++ Page: www.bloodshed.net/devcpp.html


[3] GameTutorials Message Board-->Programming Forums-->Free Dev-C++ Compiler-->OpenGL Tutorials: http://www.gametutorials.com/forum/topic.asp?TOPIC_ID=3364 (thread)


Copyright 2001-2005 Vivek Saxena. All rights reserved. Site designed, developed and maintained by Vivek Saxena. This site and all its contents are the exclusive property of Vivek Saxena. No portion of the information on this site may be reproduced in any form, without the explicit permission of the author. The author is not responsible for any damage caused by using the information mentioned on this site.