问题描述
我需要将/DEF:c:filepathmyLib.def" 命令行选项从 bash 脚本传递到 MS 编译器/链接器.路径是由 bash 脚本作为构建过程的一部分生成的.基本上,参数我的脚本通过的是:
I need to pass /DEF:c:filepathmyLib.def" command line option from a bash script to MS compiler/linker. The path is generated as part of build process by a bash script. Basically, the argument that my script passes is:
-DEF:/c/filepath/myLib.def
MSYS 路径转换 无法正确处理,因为它不理解 /DEF:
部分.如果我这样做,它会起作用
MSYS path conversion can't handle it properly because it doesn't understand /DEF:
part. It works if I do
-DEF=/c/filepath/myLib.def
但随后 ms 工具不理解此参数.简而言之,在 MSYS bash 中写入该参数以将其转换为正确参数的正确方法是什么?
but then ms tools don't understand this parameter. In short, what's the proper way to write that parameter in MSYS bash so that it converts it to proper argument?
在 cygwin 上,我可以使用 cygpath,但没有等效项,因为 msys 的某个人认为不需要它(即使有使用 cygpath 的 cygwin 脚本).
On cygwin I could use cygpath, but there is no equivalent, because somebody from msys thinks that it's not needed (even if there are scripts for cygwin that uses cygpath).
推荐答案
更新(2016 年 8 月):
这个问题不再相关,因为 msys2 现在带有 cygpath
它的安装.
This question is no longer relevant, as msys2 now comes with cygpath
in its installation.
...
我将在这里总结我的研究.
I'll summarize my research here.
MSYS 中的 cygpath 等价物是使用这个命令:
The cygpath equivalent in MSYS is to use this command:
{ cd /c/some/path && pwd -W; } | sed 's|/|\|g'
这种方法的问题在于它需要现有路径,例如c:somepath
必须是现有目录;然而,真正的 cygpath 支持不存在的路径.
The problem with this approach is that it requires existing path, e.g. the c:somepath
has to be an existing directory; however, real cygpath supports paths that do not exist.
因此,如果您需要获取不存在的目录的路径,那么您可以回退到路径的 sed 转换:
So, if you need to get path to a directory that doesn't exist, then you can fallback to sed conversion of the path:
{ cd 2>/dev/null /c/some/path && pwd -W ||
echo /c/some/path | sed 's|^/([a-z,A-Z])/|1:/|'; } | sed 's|/|\|g'
满口斜线是为了满足sed
的引用规则.因此,如果您的 PC 上不存在 c:somepath
,它会尝试将正斜杠转换为反斜杠并将 /c/
替换为 c:
(或任何其他驱动器号).唯一的缺点是它无法正常工作包含已安装组件的非现有路径,例如 /bin/does-not-exist
或 /usr/bin/does-不存在
.
The mouthful of slashes is there to satisfy quoting rules of sed
. So, if c:somepath
doesn't exist on your PC, it will try to convert forward to back slashes and replace /c/
with c:
(or any other drive letter). The only drawback for this is that it won't work correctly non-existing paths that contain a mounted component, such as /bin/does-not-exist
or /usr/bin/does-not-exist
.
另一种方法是在 MSYS 中使用来自 cygwin 的 cygpath.好像cygwin设置了全局环境变量CYGPATH,也就是可以从普通的cmd.exe中使用:
One more approach is to use cygpath from cygwin in MSYS. It seems that cygwin sets global environment variable CYGPATH, that is, you can use it from regular cmd.exe:
%CYGPATH% -w /c/some/path
C:somepath
或来自 MSYS:
$CYGPATH -w /c/some/path
C:somepath
只要您在 cygwin 中设置将 /c
指向 /cygdrive/c
即可.但是这种方法将打印位于 cygwin 安装中的 /usr
,而不是 MSYS.
as long as you set to point /c
to /cygdrive/c
in cygwin.But this approach will print you /usr
located in cygwin installation, not in MSYS.
简而言之,我认为 msys 真的应该在默认工具集中包含真正的 cygpath,只是为了某些情况下 msys 命令行参数转换逻辑没有自动处理
In short, I think msys should really include real cygpath in the default set of tools just for some cases that aren't handled automatically by msys command line argument conversion logic
这篇关于msys 路径转换(或 msys 的 cygpath?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!