0

我对使用命令行编译代码非常陌生,所以我想知道如何让 D 编译器将其所有代码编译到某个位置而不是源代码所在的位置。就像我希望最终的 .exe 和 obj 代码都在一个特定的目录中一样。我知道您可以使用 -of 命令,但我目前不知道使用它的格式。目前我有:

C:\D\dmd2\windows\bin\dmd.exe -w C:\Users\Kyle\Desktop\D\Test.d C:\Users\Kyle\Desktop\D\src\MyMod.d

我需要添加什么?

4

3 回答 3

2

使用-offilename开关。例子:

dmd factorial.d -offilename "d:\test_name.exe"

或短版:

dmd factorial.d "-ofd:\test_name.exe"

注意:如果您的路径包含空格,则双引号是必需的。

注意2:简而言之,您可以跳过.exe,但不要在完整版本中这样做,因为编译器会搜索具有该名称的源文件。

于 2013-02-18T16:24:41.550 回答
1

我知道人们不喜欢 RTFM 答案,但以下是回答您问题的 RTFM 答案:

执行dmd --help,你会得到以下信息:

DMD32 D Compiler v2.061
Copyright (c) 1999-2012 by Digital Mars written by Walter Bright
Documentation: http://www.dlang.org/index.html
Usage:
  dmd files.d ... { -switch }

  files.d        D source files
  @cmdfile       read arguments from cmdfile
  -c             do not link
  -cov           do code coverage analysis
  -D             generate documentation
  -Dddocdir      write documentation file to docdir directory
  -Dffilename    write documentation file to filename
  -d             silently allow deprecated features
  -dw            show use of deprecated features as warnings (default)
  -de            show use of deprecated features as errors (halt compilation)
  -debug         compile in debug code
  -debug=level   compile in debug code <= level
  -debug=ident   compile in debug code identified by ident
  -debuglib=name    set symbolic debug library to name
  -defaultlib=name  set default library to name
  -deps=filename write module dependencies to filename
  -g             add symbolic debug info
  -gc            add symbolic debug info, pretend to be C
  -gs            always emit stack frame
  -H             generate 'header' file
  -Hddirectory   write 'header' file to directory
  -Hffilename    write 'header' file to filename
  --help         print help
  -Ipath         where to look for imports
  -ignore        ignore unsupported pragmas
  -inline        do function inlining
  -Jpath         where to look for string imports
  -Llinkerflag   pass linkerflag to link
  -lib           generate library rather than object files
  -man           open web browser on manual page
  -map           generate linker .map file
  -noboundscheck turns off array bounds checking for all functions
  -O             optimize
  -o-            do not write object file
  -odobjdir      write object & library files to directory objdir
  -offilename    name output file to filename      <---- [1]
  -op            do not strip paths from source file
  -profile       profile runtime performance of generated code
  -property      enforce property syntax
  -quiet         suppress unnecessary messages
  -release       compile release version
  -run srcfile args...   run resulting program, passing args
  -unittest      compile in unit tests
  -v             verbose
  -version=level compile in version code >= level
  -version=ident compile in version code identified by ident
  -vtls          list all variables going into thread local storage
  -w             warnings as errors (compilation will halt)
  -wi            warnings as messages (compilation will continue)
  -X             generate JSON file
  -Xffilename    write JSON file to filename

我用[1]和箭头标记了回答您问题的行。

于 2013-02-19T08:42:14.353 回答
0

看看-of,-od-op开关。如果不知道“将其所有代码编译到某个位置”的确切含义,很难更具体。

于 2013-02-18T16:05:26.003 回答