You are on page 1of 10

Setting up DMD2 and Derelict3 on Eclipse in XP

This was a total nightmare, so I hope this helps.

Installing DMD2
1) Download the Digital Mars compiler from http://dlang.org/download.html. Choose the zip version not the Windows installer. Create a directory such as D:\programming\DMD and extract the zip there. Inside the DMD\dmd2 directory you should see something like this.

2)

3)

If you look inside the Windows folder you will find a bin folder containing the compiler executable dmd.exe. Before we configure the path go back on the net to http://www.dsource.org/projects/build/, and download Bud; the Windows Executable (I used the without debug version). Extract the executable to this bin folder and rename it bud.exe. Bud is a tool that does the job of a makefile and it seems to be required to build Derelict from source. Now we need to set the Path: a). Click Start -> Control Panel -> System, and click on the Advanced Tab.

4)

b) Just above the OK button, click on the Environment Variables button. c) In the System Variables pane you will find a field called Path, double click it.

d) At the end of the Variable value line add a semi-colon ;, and then the full path to your bin folder. e) Click OK, OK, OK. OK? 5) Now we need to configure a file called sc.ini which is located in the bin directory. Open the file in a text editor. It should look something like:

[Version] version=7.51 Build 020 [Environment] LIB="%@P%\..\lib";\dm\lib DFLAGS="-I%@P%\..\..\src\phobos" "I%@P%\..\..\src\druntime\import" LINKCMD=%@P%\link.exe The %@P% is a variable meaning the bin directory in which the sc.ini file is found. The \..\ means step up one directory. So LIB=%@P%\..\lib specifies that the path to the lib directory is one up from the bin directory, or go out of the bin directory and you will see the lib folder. You need to ensure that you directory structure is reflected in the sc.ini file. We will revisit this shortly.

6) You can test the installation: a) open the Command shell by clicking Start -> Run, and entering cmd into the Run window. At the prompt type dmd. You should see a screed of of text beginning with DMD32 D compiler b) So lets write a program. In a directory, I use c:\DMD, create a file called Main.d: import std.stdio; void main(){ writeln(Fred is nigh); } c) In the Command shell cd.. into your c:\DMD folder. Because of a mighty FU when I built the computer I seem to be committed to calling my c drive d, and my second drive c, which means Command always opens with its prompt terminating in my documents and setting folder on the d drive. To cd into c:\DMD, I first have to enter c: (without the backslash) which brings the prompt to c:\. Now I can cd DMD to get into the DMD folder. d) To compile Main.d enter dmd Main.d at the prompt. You should have a Main.exe added to your c:\DMD\ folder. You can run this by typing Main.exe at the prompt.

Installing Derelict
1) create a new folder: from bin go up to dmd2, and then open the src folder and create a new folder called etc 2) Download Derelict from https://github.com/aldacron/Derelict3 and place it in the etc folder. The Downloads button is on the right of the urld page. 3) Extract the zip. The new folder is called something like aldacronDerelict3-36a1c2e. I changed this: a) go into the extracted folder and rename the duplicate folder found there derelict b) cut/copy this derelict folder, move back into the etc directory and paste it here. Delete the original extracted folder (and all its contents if you used copy rather than cut).

You should be left with two folders in your etc directory, derelict, and the original unzipped folder.

4) Building Derelict. a) In the Command shell you need to cd into the etc\derelict\build folder where you will find a file called derelict.d b) Once in that directory, enter dmd run derelict.d at the prompt. The DMD compiler builds the Derelict libraries. The actual configuration of the path seems to be important for the build, at least from dmd2. My full path to the derelict.d file is D:\Programming\DMD\dmd2\src\etc\derelict\build\derelict.d. Also, I believe the bud.exe downloaded earlier is required to be on the path, which it will be if you have placed it in the bin directory. c) If all has gone well, the build should leave you with a set of .lib files in the lib folder. I copied them and dumped them in the lib folder under the Windows directory (same directory that you found bin in) d) I also reorganized the etc directory. The actual folders containing the openGL, SDL, etc d files are in the import\derelict folder. I cut/copy all the openGL, SDL, etc folders and placed them directly into the top level derelict folder. Thus my path to opengl3 becomes D:\Programming\DMD\dmd2\src\etc\derelict\opengl3. I deleted the import folder and any remaining contents. e) The last thing we need to do is update the sc.ini file. At the end of the DFLAGS= line, add "-I%@P%\..\..\src\etc". OpenGL can now be imported using import derelict.opengl3.gl3; Note that the import is just the continuation of the path from the etc folder, which etc folder terminates the string we added to the sc.ini file. If you do not alter the structure of the derelict folder as I did in (d), you will need to alter either the import string, or the sc.ini DFLAG string. 5) Testing the installation a) There are yet two further bits of configuration that need to be handled to get Derelict working, both of which are handled in the program you write. In (c) above I dumped all the .lib files built from Derelict into the windows/lib directory. If you look at the LIB directive in the sc.ini file you will see that it points to this lib folder

so you might think your program will know to look in the lib folder when .d files that require a lib need them. It does not! You must tell your program to include the libraries you need (ah for the simplicity of c#... except for all the bloody .net files). To do this you can use pragma(lib, "DerelictGL3.lib"); in your code after the import statements. The name of the lib matches that found in the lib folder. b) The second piece of configuration, and this one had me climbing walls trying to figure out why Derelict would not run; you must pragma in the DerelictUtil.lib because the other libraries depend on it. c) Now we can write a program that will compile under DMD/Derelict: import std.stdio; import derelict.opengl3.gl3; import derelict.sdl2.sdl; pragma(lib, "DerelictUtil.lib"); pragma(lib, "DerelictGL3.lib"); pragma(lib, "derelictSDL2.lib"); void main(){ DerelictGL3.load(); //DerelictSDL2.load(); writeln("Fred is nigh on impossible to configure"); } (written in the darkest of hours!) Save this as Main.d in the same folder as you saved the initial Main.d, and compile and run as per the earlier instructions. Note that the loading of SDL is commented out. This is because SDL requires that the standard c version of the SDL2.dll file be located in the same folder as your Main.d file. I have yet to get one of them. The openGL c libs, on the other hand, should be in your Windows System32 folder, as placed there probably by your graphics card installer.

Setting Up Eclipse for DMD/Derelict


1) I will assume you have eclipse installed. Eclipse can be downloaded from http://www.eclipse.org/downloads/. I got Eclipse Classic version. Unzip the file and you are basically set up. Just navigate to the eclipse.exe and double click it. You will have to sort out any Java dependencies on your own. 2) My interest here is how to set Eclipse up to run DMD/Derelict. To this end: a) open Eclipse and click Help -> Install New Software. b) click the Add button c) add http://ddt.eclipselabs.org.codespot.com/git.updates/ to the Location field, and DDT to the Name field.

The url can be found at http://code.google.com/a/eclipselabs.org/p/ddt/ under the Software Update Site bullet. Click OK d) With the url in the Work with field, the DDT plugins will display. Check them and finish the installation. You will need to restart Eclipse for the plugin to take effect.

e) With Eclipse restarted, click Window -> Preferences. Here we set dmd.exe as the default compiler for the d language in Eclipse. Expand DDT and select Compilers. Click the Add button and browse to the bin folder where dmd.exe is located. You should end up with the following:

If you double click on the checked dmd.exe line in the right hand pane you will see that both the phobos and the druntime src folders have been included with the dmd compiler. The importance being, that Derelict has not been.

f) We need to start a new D project. Click File -> New -> Project, and double click the D Project option.

Give the project a name in the following screen. If you look below the name field you will see and Interpreter section. This should be set with (Currently dmd.exe). The Configure Interpreters link will take you back to the screen where we set up dmd.exe as the default D compiler.

In the next screen we need to set up the path to the Derelict .d files. Select the Libraries tab, click Add External Source Folder and browse to the etc directory where you built and left your openGL/SDL folders.

Now select the Order and Export tab and check both of the libraries

I left the next screen alone and finished the New Project wizard. In either the Script Explorer or the Project Explorer panes to the left of Eclipse, right click on the src folder, hover over the New option and click the File menu item that displays. Name the file Main.d and fill it with the same content as the last Main.d you wrote. When you click ctrl s, the file will save and compile leaving a description of dmds findings in the bottom Console window. You can now click the green arrow in the toolbar to run the program.

You might also like