Compile D project with DMD

375 Views Asked by At

This might be stupidiest and newbie's question, but how do I actually compile D project with DMD on windows?

I tried these commands:

  • dmd *
  • dmd *.d
  • cd .. && dmd {DirectoryName}
  • dmd file1.d file2.d

But neither of them compile the project to executable.

I want to produce .exe file out of that project, but it seems I can't. I can only compile one file in the project or compile multiple, but only .obj file, not .exe...

2

There are 2 best solutions below

0
Arun On BEST ANSWER

DUB is the easiest for beginners:

C:\Users\217216x715132\Desktop\tmp1>dub init
Package recipe format (sdl/json) [json]:
Name [tmp1]:
Description [A minimal D application.]:
Author name [217216X715132]:
License [proprietary]:
Copyright string [Copyright © 2019, 217216X715132]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in 'C:\Users\217216x715132\Desktop\tmp1'.
Package successfully created in .

C:\Users\217216x715132\Desktop\tmp1>dub run
Performing "debug" build using dmd for x86.
tmp1 ~master: building configuration "application"...
Linking...
Running .\tmp1.exe
Edit source/app.d to start your project.

C:\Users\217216x715132\Desktop\tmp1>

You can copy all your d files to your-project\source\ directory and let dub do all the hard work.

dub init doesn't work from git bash for some reason, as it waits for input on CLI. So you need to dub init from cmd.exe. dub run should work fine from git bash.

If you run it from git bash, press enter key 7 times, all the defaults will be accepted and the project will be created.

arun MINGW64 ~/Desktop/tmp1$ dub init







Package recipe format (sdl/json) [json]: Name [tmp1]: Description [A minimal D application.]: Author name [217216X715132]: License [proprietary]: Copyright string [Copyright © 2019, 217216X715132]: Add dependency (leave empty to skip) []: Successfully created an empty project in 'C:\Users\217216x715132\Desktop\tmp1'.
Package successfully created in .

arun MINGW64 ~/Desktop/tmp1$

Related issue in DUB

0
EricP On

If you don't like Dub, you might try rdmd, which comes with the standard D compiler. E.g suppose you have a main.d file that imports other files:

rdmd --build-only main.d            # Build
rdmd --build-only -g -debug main.d  # Build in debug mode
rdmd main.d                         # Build temporary executable and run it

If you want to see the raw commands that dub executes to build your project, you can use:

dub build --force --verbose