【问题标题】:Configuring DUB to use 64-bit compiler配置 DUB 以使用 64 位编译器
【发布时间】:2017-05-19 15:23:23
【问题描述】:

如何配置 DUB 以将我的应用程序编译为 64 位可执行文件?这是我的 dub.json:

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

我尝试将此行添加到 dub.json:

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

然后dub build 输出:

## 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.

所以我尝试将这一行替换为:

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

但出现此错误:

Error: unrecognized switch '--arch=x86_64'

我使用的是 Windows 10,已安装 DMD 2.074.0 和 Visual Studio 2015 和 2017。

【问题讨论】:

  • 您是否尝试手动编译和链接一个小型 D 程序?我怀疑你没有配置你的环境。如您所知,DUB 正在使用编译器/链接器 - 如果您没有正确设置它,编译/链接将失败。可能根本不是 DUB 问题...对于链接,如果我没记错的话,DMD 使用 Microsoft 链接器。
  • 我可以编译和链接其他 D 程序,但这是我第一次尝试构建 64 位程序并运行 dmd --arch=x86_64 source\app.d 给出相同的错误。
  • 据我所知 dmd 没有该选项。它只有-m64 ...这正是我问的 - 你能成功编译(使用 DMD)你想要的目标吗???
  • 是的,刚刚测试过。命令行上的dmd支持-m64,但是在dub中不行。
  • dub build --arch=x86_64 应该在一切配置良好的情况下进行。

标签: d dub


【解决方案1】:

我很确定(如果我错了,请纠正我)您没有为 64 位环境正确配置 DMD。

看看http://dlang.org/dmd-windows.html#environment 。 - 关键信息是您需要正确设置 LINKCMD64 变量。示例:set LINKCMD64=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe

然后您指示 DMD 编译器(带有-m64 选项)编译 D 代码并使用 Microsoft 的链接器生成 64 位可执行文件。

最后,您需要修改 JSON 或 SDL DUB 文件以包含正确的环境设置。 (看看https://code.dlang.org/package-format?lang=json#target-types)

如果您没有在 DUB 文件中指定环境,则必须在您的 dub build 中明确提供它。示例:dub build --arch=x86_64

【讨论】:

  • 问题似乎是dub不接受-m64,即使设置了环境变量。
  • “目标类型”部分告诉我们有关架构/环境设置的哪些信息?它似乎决定了项目是如何链接(或不链接)的,所以我不清楚这种关系。
猜你喜欢
  • 2014-08-15
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
  • 2018-03-22
  • 1970-01-01
  • 2018-05-02
  • 1970-01-01
  • 2014-02-23
相关资源
最近更新 更多