The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Build/DMC

From Allegro Wiki
Jump to: navigation, search

Requirements

Setting up DMC

  1. Unzip the Digital Mars compiler (dmc.zip) and place the files in c:\dmc.
  2. Unzip the Basic Utilities (bup.zip) and place them in the same folder. (The exe files should all be in the c:\dmc\bin folder.)
  3. Unzip the DirectX 7 package (dx70_dmc.zip) and place the include files in c:\dmc\include and the library files in c:\dmc\lib. (This will overwrite some of DMC's default DX files.)
  4. Extract only the usr/local/wbin/make.exe file from UnxUtils.zip to your desktop, rename it to gmake.exe, and copy it to c:\dmc\bin.
  5. Add c:\dmc\bin to your PATH environment variable.
  6. Create the DMCDIR environment variable and set it to c:\dmc

Building Allegro

  1. Extract the Allegro source zip file to c:\allegro
  2. Open up a MS-DOS prompt.
  3. Type cd\allegro to change to the Allegro folder.
  4. Type fix dmc
  5. Type gmake obj\dmc\plugins.h
  6. Type gmake all ALLEGRO_USE_C=1 STATICLINK=1 to build the static Release, Profiling, Debugging and versions.
  7. Type gmake installall ALLEGRO_USE_C=1 STATICLINK=1 to install the static libraries.
  8. Type gmake all ALLEGRO_USE_C=1 to build the dynamic Release, Profiling, Debugging and versions.
  9. Type gmake installall ALLEGRO_USE_C=1 to install the dynamic libraries.

Advanced Build Options

The above instructions build six versions of Allegro, the Demo, tools, examples, and the documentation. If you don't need all of that, you can customize what gets built. Obviously, if you don't need both the static or dynamic libraries, simply don't run the associated commands. If you don't care about the Debugging or Profiling versions, you can remove the word all from the command line. For example:

gmake ALLEGRO_USE_C=1
gmake install ALLEGRO_USE_C=1

builds and installs the optimized, dynamic Allegro library along with all of the examples, documents, etc. Or if you want to specifically build and install the debug and profiling versions:

gmake ALLEGRO_USE_C=1 DEBUGMODE=1
gmake install ALLEGRO_USE_C=1 DEBUGMODE=1
gmake ALLEGRO_USE_C=1 PROFILEMODE=1
gmake install ALLEGRO_USE_C=1 PROFILEMODE=1

If you only want to build the library (without the extra stuff), specifically request to make the lib target:

gmake lib ALLEGRO_USE_C=1

That would only build the optimized, dynamic Allegro library. Other targets besides lib exist; refer to Makefile.all and Makefile.dmc for more information. All of the options can be mixed and matched where it makes sense.

Note that DMC can only build the C version of Allegro (as opposed to using some assembly), so the ALLEGRO_USE_C=1 option is mandatory.

Using Allegro

For a simple example, consider hello.c: <HighlightSyntax language="cpp">

  1. include <allegro.h>

int main(void) {

 allegro_init();
 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0,0);
 allegro_message("Hello, World!");
 return 0;

} END_OF_MAIN() </HighlightSyntax> First, you must include the Allegro header file. Inside the main function, you should call allegro_init() to set up Allegro. You must do that before calling (almost) any of the other Allegro functions. (This program will create a 640x480 window and then pop-up the message "Hello, World!".) At the end of the main function, you must include the END_OF_MAIN() macro (no semicolon is needed).

Dynamic Version (DLL)

To compile this program, type:

dmc -c test.c

This will create the object file. It will then need to be linked to Allegro when you create the executable:

dmc test.obj alleg.lib -otest.exe

That will build test.exe, which will require the Allegro DLL (eg: alleg42.dll) to run. Alternatively you could use allp.lib for profiling or alld.lib for debugging.

Static Version

If you wanted to statically link this program so that the Allegro DLL is not required, you must first compile it like:

dmc -c test.c -DALLEGRO_STATICLINK=1

Then you can link it against any of the static versions of Allegro:

dmc test.obj alleg_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib 
    ddraw.lib winmm.lib dsound.lib dxguid.lib

(All of that should be entered on one line.) Note that you have to include a bunch of Windows libraries when you statically link! As before, you can also use allp_s.lib for profiling and alld_s.lib for debugging.