How to Use the Digital Mars C/C++ Compiler (DMC) for Command-Line Development
Digital Mars C/C++ (DMC) is a high-performance, fast-compiling compiler for Windows known for its speed and compact footprint. While many modern developers use heavy Integrated Development Environments (IDEs), using DMC from the command line offers a lightweight, efficient workflow, especially for quick testing or legacy development.
This article will guide you through installing, configuring, and using the DMC compiler to build C and C++ applications from the command prompt. 1. Downloading and Installing DMC DMC is a free, command-line-focused compiler.
Download: Download the Digital Mars C/C++ compiler from the official website.
Install: Extract the zip file (e.g., dm857c.zip) to the root of your hard drive, typically C:\dm. This ensures the directory structure (\dm\bin, \dm\lib) remains intact. 2. Configuring Your Environment (PATH)
To run dmc from any directory in the Command Prompt, you need to add the compiler’s bin folder to your Windows system path.
Open the Start Menu and search for “Edit the system environment variables.” Click on Environment Variables.
Under System Variables, find and select Path, then click Edit.
Click New and add the path to your bin directory (e.g., C:\dm\bin). Click OK on all windows to save changes.
Alternatively, you can manually use the full path, such as \dm\bin\dmc, in your console. 3. Basic Compiling Example Let’s create a classic “Hello World” program.
Create a Source File: Open a text editor and save the following code as hello.c:
#include Use code with caution.
Open Command Prompt: Navigate to the folder where you saved hello.c. Compile: Run the following command: dmc hello.c Use code with caution.
This command compiles the source code and links it to create hello.obj and the final executable hello.exe. Run: Execute the program: hello Use code with caution. 4. Key Command-Line Options
The Digital Mars compiler (dmc) supports several flags to customize the compilation process:
dmc -c file.c: Compiles only, producing an object file (.obj) without linking.
dmc -o+speed: Enables optimizations for faster execution code. dmc -w: Turns on warnings. dmc -g: Adds debugging information to the executable.
dmc -cpp: Forces compiling as C++ code, even if the file extension is .c. 5. Understanding sc.ini (Compiler Settings)
DMC uses a configuration file named sc.ini located in the \dm\bin directory to define default include paths, library paths, and compiler flags.
If you move the compiler or need to change default library paths, edit sc.ini. It should resemble this: [Environment] INCLUDE=%@P%..\INCLUDE LIB=%@P%..\LIB Use code with caution.
%@P% is a special variable that represents the path where dmc.exe resides. 6. Compiling Multi-File Projects
For larger projects, you can compile multiple source files and link them together: dmc main.c functions.c Use code with caution.
This generates main.obj, functions.obj, and links them into main.exe.
The Digital Mars C/C++ Compiler is an excellent choice for developers who prefer command-line tools. By configuring the system PATH and understanding the basic dmc commands, you can enjoy a very fast, efficient development cycle. If you’d like to dive deeper, I can help you with: Setting up Makefiles for automation. Linking external libraries.
Optimizing your code specifically for the Digital Mars compiler. Compiling Code – Digital Mars
Leave a Reply