【问题标题】:How to change drive in Makefile?如何在 Makefile 中更改驱动器?
【发布时间】:2020-02-06 07:42:11
【问题描述】:

我的 Makefile 中的目标(规则)有一系列命令。前几个命令应该从 D:\ 驱动器执行。在此之后,我应该将我的目录更改为 C:\,以便我可以在 C:\ 驱动器中执行文件。但是,我无法更改驱动器。我尝试了以下方法:

  • C:(在 cmd 中有效,但在 Makefile 中无效)
  • cd /d C:(不工作)
  • cd C:(不工作)

请告诉我如何在 make 规则中更改驱动器。

【问题讨论】:

  • 正如stackoverflow.com/questions/40455549/… 中的建议,您可以尝试在目录名称中使用斜杠而不是反斜杠
  • 驱动器号不是路径,驱动器的根路径由单个斜杠引用,(在 Windows 中向后,在 nix 中向前)。因此,您要查找驱动器号,然后是其根驱动器。 CD /D C:` will change the current directory to the root of the C:` 驱动器。 CD /D D:` will change the current directory to the root of the D:` 驱动器。 /D 选项允许在驱动器之间移动,而不仅仅是同一驱动器内的位置。如果您不确定当前目录,包含该选项总是更安全。
  • 另请注意,您不必更改当前目录或驱动器即可执行命令。您也可以使用PushD 作为替代,PushD C:\ PushD D:\ ,但请记住每个都使用PopD,以便之后返回上一个位置。

标签: bash cmd makefile gnu-make


【解决方案1】:

这可以通过使用 ;或 && \

cd d:\folder1 && \
dir && \
echo "all files in d:\folder1 are listed"

cd c:\folder2 && \
dir && \
echo "all files in c:\folder2 are listed"

等价于

cd d:\folder1; dir; echo "all files in d:\folder1 are listed"

cd c:\folder2; dir; echo "all files in c:\folder2 are listed"

【讨论】:

  • cd 不会更改当前驱动器,除非给出/d,这是cmd 特定的。为了可移植性,我会使用pushd,它恰好可以与cmd、PowerShell 和基于Linux 的shell 一起使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-18
  • 1970-01-01
  • 2010-12-28
  • 1970-01-01
  • 1970-01-01
  • 2016-11-28
  • 1970-01-01
相关资源
最近更新 更多