3

How do I configure DUB to compile my application as 64-bit executable? Here's my dub.json:

{
    "name": "dvulkanbase",
    "targetType": "executable",
    "description": "Vulkan boilerplate",
    "authors": ["Myself"],
    "homepage": "http://something",
    "license": "MIT"
}

I tried adding this line to dub.json:

    "dflags-dmd": ["-m64"]

but then dub build outputted:

## Warning for package dvulkanbase ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

-m64: Use --arch=x86/--arch=x86_64/--arch=x86_mscoff to specify the target architecture

Performing "debug" build using dmd for x86.

So I tried replacing the line with:

"dflags-dmd": ["--arch=x86_64"]

but got this error:

Error: unrecognized switch '--arch=x86_64'

I'm on Windows 10, have DMD 2.074.0 and Visual Studio 2015 and 2017 installed.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • Did you try to manually compile and link a tiny D program? I suspect you did not configure your environment. As you know, DUB is using the compiler/linker - if you did not set it up properly, compilation/linking will fail. It may not be a DUB problem at all... For linking, DMD uses Microsoft linker if I remember well. – DejanLekic May 19 '17 at 15:29
  • I can compile and link other D programs, but this is the first time I'm trying to build 64-bit programs and running `dmd --arch=x86_64 source\app.d` gives the same error. – SurvivalMachine May 19 '17 at 15:37
  • As far as I know dmd does not have that option. It only has `-m64` ... THAT is precisely what I asked - can you compile successfully (using DMD) for the target you want??? – DejanLekic May 19 '17 at 15:48
  • yup, just tested. dmd on the command line supports `-m64` but it doesn't work in dub. – SurvivalMachine May 19 '17 at 15:52
  • `dub build --arch=x86_64` should do if everything is configured well. – DejanLekic May 19 '17 at 15:59
  • @DejanLekic That did it! The correct environment variable on my system was "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe" – SurvivalMachine May 19 '17 at 16:06
  • Ideally you do not have to specify the arch in the command line. – DejanLekic May 19 '17 at 16:12

1 Answers1

2

I am pretty sure (correct me if I am wrong) that you did not configure DMD properly for the 64bit environment.

Have a look at http://dlang.org/dmd-windows.html#environment . - The key information there is that you need to set LINKCMD64 variable correctly. Example: set LINKCMD64=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe

Then you instruct the DMD compiler (with the -m64 option) to compile the D code and use Microsoft's linker to generate 64bit executable.

Finally, you will need to modify your JSON or SDL DUB file to contain proper environment settings. ( Have a look at https://code.dlang.org/package-format?lang=json#target-types )

If you do not specify the environment in the DUB file, you will have to explicitly provide it in your dub build. Example: dub build --arch=x86_64

DejanLekic
  • 18,787
  • 4
  • 46
  • 77
  • The problem seems to be that dub doesn't accept `-m64` even after setting the environment variable. – SurvivalMachine May 19 '17 at 15:56
  • What does the "Target types" section tell us about architecture/environment settings? It seems to dictate how the project is linked (or not linked), so the relationship is not clear to me. – chadjoan Jun 21 '17 at 00:43