Tutorial 0 : Installing a development environment for Windows
Installing a development environment is not generally a difficult task but it is important to understand which components should be installed and how to test them when the installation process is not fully automatic.
During that tutorial, we will be installing :
- The compilers DMC and DMD so we can compile D source files (DMD uses DMC even if there is no dependency between C and D languages).
- A Toolchain, MinGW, that makes it possible to compile a big project using configuration files without writing lots of console garbage.
- An IDE, Code::Blocks, which drives all the compiling / linking process from a friendly graphical interface.
- More libraries like Derelict, SDL/OpenGL and extensions that makes it possible to use advanced functionalities like 2D/3D graphics and file loading without restarting all from scratch.
During each steps, you should store downloaded files in separate folders that will contain those files only. It is easier if you have to restart from a previous step.
All the installation process I describe is done on the c:\ drive, you will have to adapt all path depending on your own installation drive.
My installation is done on a Windows 7, but it will be the same process if you use a previous Windows version.
Compilers : dmc and dmd
Download dmc.zip and dmd.1.xxx.zip on Digital Mars website dmc and dmd |
It is wise to use the version 1.xxx of DMD while the version 2 is an alpha that can potentially be unstable.
Uncompress both archives on your C drive, you should now have c:\dm and c:\dmd
To tell Windows where the compiler executables are, you have to add c:\dm\bin and c:\dmd\windows\bin to you PATH system variable. Depending on your Windows version you might have to relogon after applying changes.
It is optional but highly recommended that you perform a quick test to see if the installation is working. Open a console by pressing Win + R and typing cmd. Type cd c:\dmd\samples\d\ to go to the example folder. Type dmd hello.d. If it works, dmd compiles hello.d without displaying any message. If it displays an error, check that your PATH variable is up-to-date and is set accordingly to then content of c:\dm and c:\dmd. If everything goes well, type hello and the program should answer "hello world".
It is highly recommended to install compilers with an automatic installer when possible, for DMD, it has to be setup manually.
Toolchain : MinGW
Download "Automated MinGW Installer" on SourceForge.net Automated MinGW Installer |
We will now install MinGW, which will makes it easier to manage big projects using configuration files. Don't panic, the installation process is almost automatic and most MinGW functionalities will be masked by the IDE with which any task will be performed using a friendly graphic interface.
After downloading the most up-to-date version of "Automated MinGW Installer" (MinGW-xxx.exe), store it in a folder that will contain only that file. The installer will download more files and store them in that folder during the installation process :

Select current to install the stable version :

In the component selection dialog, you have to select at least "MinGW base tools", you can also select any additional compiler you need:

After the installation process is finished, you still have to tell Windows where to find the MinGW executables by adding c:\mingw\bin to your PATH system variable.
IDE : Code::Blocks - Installation
|
Go to the code::blocks forum here and select the subject corresponding to the most up-to-date version of code::blocks Then download wxmsw28u_gcc_cb_wxXXXX.7z and CB_XXXXXXXX_revYYYY_win32.7z (The MinGW DLL version is useless as we just installed it before). You will need 7Zip to uncompress the archives, it can be found here : |
We will be using code::blocks and to ensure our version is the most up-to-date, we will install a nightly build. That version is still in development and might contains bugs but it allows us to have all the newest functionalities. In case a version is unstable you can use a previous version or the latest stable version.
You will need the wxWidget DLL (wxmsw28u_gcc_cb_wxXXXX.7z), the API use for code::blocks graphical interface.
You will also need the code::blocks archive (CB_XXXXXXXX_revYYYY_win32.7z).
No need to use the MinGW DLL as we just installed it before.
Uncompress both archives in c:\codeblocks, the code::blocks archive first, then the wxWidget DLL. You can also create a code::blocks shortcut on your desktop or you start menu if you want.
IDE : Code::Blocks - Configuration
When you launch code::blocks the first time, it will ask if you want to associate it with source files and display a window listing all known compilers. DM and G++ should be detected by default but due to a specific folder tree, DMD is likely not to be detected automatically and will require to be configured manually. In case you need it, code::blocks configuration files can be found in C:\Users\Your_user_account\AppData\Roaming\codeblocks on Windows 7)
Before configuring code::blocks, you need to know that there is two ways to change a parameter. You can make a change available to all projects by changing the global parameters or you can make the change to a single project by changing the project properties. When configuring a compiler, you will need to change global parameters to indicate code::blocks where to find the compiler definition files (*.h or *.d) and libraries (*.lib).
Go to Settings->Compilers and debuggers and select Digital Mars D Compiler in the list:

First in the Toolchain executables tab set the compiler's installation directory to c:\dmd\windows\ as the bin folder is here, you should also add it to the "Additional path" sub tab. All the executables names in the "Program Files" sub tab should be valid so no need to change them.
Then you will need to indicate where to find the definition files and libraries. In the "search directories" there is three sub tabs, the first indicates where are the definition files used by the compiler. The path should points to c:\dmd\src\phobos. The second tab indicates where are the libraries used during the linking process, it should point to c:\dmd\windows\lib. The third sub tab is used for specific ressource files, we doesn't need it yet.
The last detail is to select DMD as your default compiler if you use it often or if it is your only D compiler. Just click on Set as default on the top area of the window.
IDE : Code::Blocks - Test
We will be creatin a new project to test the installation using File->New project and selecting D Application :

Give a name to your project and set the path where it should be stored :

Check Digital Mars D Compiler as the default compiler for this project :

Clic Finish and open hello.d located on the left tab to get an overview of a small D program. Press F9 to compile and execute the application, if it goes well a console window should display "hello world".
If an error occurs, you should go back few steps and check that you are using DMD and not another compiler, that code::blocks uses the right access path for executables and files and that MinGW and the compilers (dmc and dmd) are correctly installed.
API: Derelict and SDL/OpenGL - Installation
Download "The D Shared Software System" on DSource.org (dsss-X.YY-x86-windows.zip) DSSS |
Derelict makes it possible to call functions from C libraries like SDL, OpenGL and others from a D application. Some of you might think that it is useless to code in D if most of the time we keep calling C functions. That is true a completely object oriented D API would be better but the good thing is that those who knowns how to use the C libraries will have little to learn to use them from D. Others API can be found at http://www.dsource.org/
The easiest way to install Derelict is to use DSSS (The D Shared Software System), uncompress dsss-X.YY-x86-windows.zip in c:\dsss and add c:\dsss\bin to the PATH system variable.
You can find detailed instructions on how to use DSSS in C:\dsss\share\doc\dsss\README.use
To keep things simple, DSSS can download, compile and install Derelict where you want. Open a console using Win +
R keys and type cmd.
Type dsss net install --prefix=c:\dmd derelict and select the mirror DSSS should use to download Derelict.
You have now few minutes to get yourself a coffee.
It is important to understand that DSSS creates the c:\dmd\include folder that contains all the definition files (*.d)and the c:\dmd\lib folder that contains all the library files (*.lib). Those folders are unknown to code::blocks and DMD so we have to configure the path to access them during compilation.
I chose to let Derelict files in separate folders but you could move the content of the new lib folder in c:\dmd\windows\lib so all files are stored in the default librarires location. You could do the same for the content of c:\dmd\include and move it to c:\dmd\src.
API: Derelict and SDL/OpenGL - Configuration
This time we will configure code::blocks in two steps, first we will set Derelict's definition files and libraries path using Settings->Compiler and debugger
and then selecting Digital Mars D Compiler in the scrolling menu. In Search directories->Compiler add c:\dmd\include\d
In the linker sub tab, add c:\dmd\lib
When using APIs like SDL you have to specify all the libraries file name you want to use one by one. As those files might not be linked to all your D applications,
you should use the project properties to specify them rather than the global parameters.
Go to Projetc->Build options and select debug in the left panel. In the "Linker Settings" tab clic add, a new window appear. Clic on
... to open the selection window, go to c:\dmd\lib (the folder containing all the Derelict's .lib files)
and select all the .lib files you need. If you are not sure which one you are going to use, you can select them all. Code::blocks will ask you if you want to keep
path relative to the DMD install folder, better answer Yes. All the files you selected should now be visible in the file list, clic
Ok.
You have to follow the same process to configure the Release version (select release in the left panel).
API: Derelict and SDL/OpenGL - Test
Download all the DLL runtime of the libraries you are going to use. |
To do a quick test of your Derelict installation, replace the content of hello.d with this code, save it and press CTRL + F9 keys to compile the project. If the compilation goes well, the configuration is finished. Press F9 to start the application and ... It doesn't work because the SDL DLLs are not in the project folder.
Uncompress the DLL archives and copy them in the root of the project (the folder containing the .cbp file), go back to code::blocks and press F9 again to execute the program. If all goes well a black window should appear using SDL.

