`
sofire
  • 浏览: 144111 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[zt]D语言编译器下载安装和编译参数

阅读更多

Javaeye的html编辑器用起来不爽。
不知道怎么用UBB标签的表格标签。

by: D语言论坛 http://bbs.yidabu.com/forum-10-1.html
from: http://digitalmars.com/d/dcompiler.html
version: 基于D 1.014

D语言编译器下载

最新版DMD编译器下载(Win32,Linux)
http://ftp.digitalmars.com/dmd.zip

最新版DMC下载(Win32,包含链接器和工具)
http://ftp.digitalmars.com/dmc.zip

任意版本DMD下载:
http://digitalmars.com/d/changelog.html

Win32和Linux通用的文件说明:
\dmd\src\phobos\
运行时标准库源文件

\dmd\src\dmd\
DMD编译器前端源文件

\dmd\html\d\
文档

\dmd\samples\d\
示例程序

Win32 D语言编译器

1 安装需求
1.1 32位Windows(Win32)操作系统,比如Windows XP

1.2 下载D语言编译器DMD.zip
 http://ftp.digitalmars.com/dmd.zip

1.3 下载链接器和工具DMC.zip
 http://ftp.digitalmars.com/dmc.zip

2 主要文件

\dmd\bin\dmd.exe
D语言编译器可执行文件

\dmd\bin\shell.exe
简单的命令行shell

\dmd\bin\sc.ini
D语言编译器全局设置

\dmd\lib\phobos.lib
D运行时库文件

3 安装指南

打开控制台窗口(Windows XP只要点击[开始][命令提示符])。
所有工具都是命令行工具,也就是说只能在控制台窗口里运行。
切换到你安装D的根目录,解压下载下来的文件,dmd.zip会创建\dmd目录,dmc.zip会创建\dm目录。
操作过程可能是这样:更详细的安装指南可以参考D语言论坛 http://bbs.yidabu.com/forum-10-1.html
http://bbs.yidabu.com/thread-456-1.html

  1. D:\d>cd \   
  2. D:\d>unzip dmd.zip   
  3. D:\d>unzip dmc.zip  

 4 编译示例
\dmd\samples\d目录下有许多示例程序,进入目录
命令行执行: 

  1. \dmd\bin\shell all.sh  

可以编译示例程序。
更详细的图文教程见这里:
http://bbs.yidabu.com/thread-457-1.html

5 编译器参数和开关节

基本的命令格式如下:files可以是: 

  1. dmd files... -switches...  

Extension File Type
none D source files
.d  D source files
.di D interface files
.obj Object files to link in
.lib Object code libraries to search
.exe Name output executable file
 .def module definition file
 .res resource file

@cmdfile
从文本文件中读入编译器参数和开关

-c
只编译不链接.

-cov
代码覆盖率分析指令

-D
从源文件中产生文档

-Dddocdir
把文档写到docdir目录

-Dffilename
把文档写到filename

-d
allow deprecated features

-debug
编译进调用代码

-debug=level
编译进<= level 的调试代码

-debug=ident
compile in debug code identified by ident

-g
add CodeView 4 symbolic debug info

-gc
add CodeView 4 symbolic debug info in C format (for C debuggers)

-H
生成D接口文件

-Hddir
把D接口文件写到dir目录

-Hffilename
把D接口文件写到filename

--help
在控制台输出帮助

-inline
inline expand functions

-Ipath
import路径。可以用;分隔。可以有多个-I。照给定路径顺序搜索。

-Jpath
Import表达式导入文件的搜索路径,其他同-Ipath
示例如:
有一个test.d主要代码如下 :

假设temp.html的绝对路径是:D:\temp.html
进入test.d所在目录,在控制台窗口执行:
[Copy to clipboard] [ - ]
CODE:
dmd test.d -JD:\

-Llinkerflag
pass linkerflag to the linker, for example, /ma/li

-nofloat
Prevents emission of __fltused reference in object files, even if floating point code is present. Useful for library code. Windows only.( 本文出处: http://bbs.yidabu.com/forum-10-1.html )

-O
优化生成代码

-o-
不生成object文件。一般和-D,-H开关同时使用。
Suppress generation of object file. Useful in conjuction with -D or -H flags.

-odobjdir
write object files relative to directory objdir instead of to the current directory
把object文件写到当前目录的相对目录里。
比如下面命令生成object\test.obj和test.exe,test.map

dmd test.d -odobject

-offilename
设置输出文件名
比如:
[Copy to clipboard] [ - ]
CODE:
dmdtest.d -ofmy

会输出my.exe( 本文出处: http://bbs.yidabu.com/forum-10-1.html )

-op
normally the path for .d source files is stripped off when generating an object file name. -op will leave it on.
-profile
profile the runtime performance of the generated code

-quiet
关闭不必要的编译器消息

-release
编译发行版,也就是不生成契约和断言代码

-run srcfile args...
compile, link, and run the program srcfile with the rest of the command line, args..., as the arguments to the program. No .obj or .exe file is left behind.

-unittest
编译进单元测试代码(还有断言)
compile in unittest code, also turns on asserts( 本文出处: http://bbs.yidabu.com/forum-10-1.html )

-v
verbose

-version=level
compile in version code >= level

-version=ident
compile in version code identified by ident

-w
enable warnings

5 Linking链接

dmd编译器编译成功后会直接执行链接操作,不要链接就加上-c编译开关。

编译程序时必须链接D运行时库phobos.lib和C运行时库snn.lib,如果LIB环境变量设置正确,这些操作都会自动进行的。
一般这样设置:
QUOTE:
set LIB=\dmd\lib;\dm\lib

6 Environment Variables环境变量

D程序编译器dmd使用下面的环境变量:
1.1 DFLAGS

这里的值相当于dmd.exe的命令行参数
D语言论坛 http://bbs.yidabu.com/forum-10-1.html 举个简单的例子:
可以把自己写的或收集的模块放在\dmd\src\my\目录下,然后设置
QUOTE:
DFLAGS="-I%@P%\..\src\phobos;%@P%\..\src\my"

这样以后用到my下的模块时编译就省去写-I参数了

1.2 LIB

链接器搜索库文件的路径。
一般是这样的:( 本文出处: http://bbs.yidabu.com/forum-10-1.html )
QUOTE:
set LIB=\dmd\lib;\dm\lib

1.3 LINKCMD

dmd所启动的链接器的路径,你也可以指定为另外的链接器来代替:
QUOTE:
set LINKCMD=\dm\bin\link

1.4 PATH

如果dmd.exe找不到链接器,就会搜索PATH。注意:别的link.exe可能导致出错,确保在PATH搜索中首先找到Digtal Mars的link.exe,或者用LINKCMD指定链接器路径。
按:PATH设置图文教程见:http://bbs.yidabu.com/thread-457-1.html

7 sc.ini Initialization File

dmd会按照下面的目录顺序查找初始化文件sc.ini
QUOTE:
当前工作目录
HOME环境变量指定目录
dmd.exe所在目录

如果找到sc.ine,会覆盖掉任何已有设置。这样可以方便地为不同程序设置不同的环境变量。

环境变量在[Environment] 下面,形式是NAME=value键值对. NAME都大写,分号;开始行是注释

  1. ; sc.ini file for dmd   
  2. ; Names enclosed by %% are searched for in the existing environment   
  3. ; and inserted. The special name %@P% is replaced with the path   
  4. ; to this file.   
  5. [Environment]   
  6. LIB="%@P%\..\lib";\dm\lib   
  7. DFLAGS="-I%@P%\..\src\phobos"  
  8. LINKCMD="%@P%\..\..\dm\bin"  
  9. DDOCFILE=mysettings.ddoc  
8 常见按照问题

Using Cygwin's unzip utility has been known to cause strange problems.
Running the compiler under Cygwin's command shell has been also known to cause problems. Try getting it to work under the regular Windows shell cmd.exe before trying Cygwin's.
dmd和dmc按装目录带空格会有问题。
General一般性说明

1 D接口文件

当处理源文件中的import声明时,编译器会搜索import对应的源文件,从中提取出需要的信息。编译器同时也会搜索D接口文件,D接口文件中只包含模块中需要导入的内容,而不是整个模块。
使用D接口文件的好处是:

D接口文件更小,和D源文件相比处理起来更快。
可以隐藏源代码。比如以接口文件和object库的方式提供源程序,而不是提供全部源代码。

D接口文件可以在编译D源文件时用-H开关创建,D接口文件的后缀是.di。当编译器分解import声明时,搜索寻找.di形式的D接口文件,再寻找D源文件。
D接口文件有点和C++头文件相似,但这不是必需的,它不属于D语言,只是编译器的一个功能,只是用来优化程序的构建。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics