Search code examples
ddub

Configuring DUB to use 64-bit compiler


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.


Solution

  • 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