windows mingw make 无法处理路径中的空格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5999507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mingw make can't handle spaces in path?
提问by olamundo
I am trying to compile code, the makefile created using qmake. When I run mingw32-make I get the following error:
我正在尝试编译代码,即使用 qmake 创建的 makefile。当我运行 mingw32-make 时,出现以下错误:
cd bzip2-1.0.5\ && c:\QtSDK\Desktop\Qt.7.3\mingw\bin\qmake.exe c:\Documents an
d Settings\user\My Documents\Visual Studio 2010\Projects\meshlab\meshlab\meshla
b\src\external\bzip2-1.0.5\bzip2-1.0.5.pro -o Makefile
Cannot find file: c:\Documents.
Cannot find file: and.
Cannot find file: Settings\user\My.
Cannot find file: Documents\Visual.
Cannot find file: Studio.
Cannot find file: 2010\Projects\meshlab\meshlab\meshlab\src\external\bzip2-1.0.5
\bzip2-1.0.5.pro.
mingw32-make: *** [bzip2-1.0.5\Makefile] Error 2
By the error it appears that mingw32-make doesn't understand paths that have spaces in them. Is that true? Is there a way around it?
通过错误似乎 mingw32-make 不理解其中有空格的路径。真的吗?有办法解决吗?
采纳答案by paxdiablo
From the MinGW "Getting Started" guide:
来自MinGW“入门”指南:
MinGW may have problems with paths containing spaces, and if not, usually other programs used with MinGW will experience problems with such paths. Thus, we strongly recommend that you do not install MinGW in any location with spaces in the path name reference; i.e. you should avoid installing into any subdirectory of "Program Files" or "My Documents", or the like.
MinGW 可能会遇到包含空格的路径问题,如果没有,通常与 MinGW 一起使用的其他程序会遇到此类路径的问题。因此,我们强烈建议您不要将 MinGW 安装在路径名引用中有空格的任何位置;即您应该避免安装到“Program Files”或“My Documents”等的任何子目录中。
I suspect the same problems found in running executable files will also manifest itself with other files as well. You could try wrapping the whole thing (file specification) inside double quotes and this maywork but Windows is sometimes not as logical as UNIX-based shells in this area.
我怀疑在运行可执行文件时发现的相同问题也会在其他文件中表现出来。您可以尝试将整个内容(文件规范)括在双引号内,这可能会奏效,但 Windows 在这方面有时不像基于 UNIX 的 shell 那样合乎逻辑。
Spaces in file names are evil anyway :-)
无论如何,文件名中的空格都是邪恶的:-)
回答by Aleksandr Dubinsky
The common way to do it in Linux/UNIX is to escape each space with a backslash, like: /c/Documents\ and\ Settings/User
However, this doesn't always work in MinGW.
在 Linux/UNIX 中执行此操作的常用方法是使用反斜杠对每个空格进行转义,例如:/c/Documents\ and\ Settings/User
但是,这在 MinGW 中并不总是有效。
So, use the short (8.3) name. You get the short name with the Windows (not MinGW) command for %I in (<PATH>) do @echo %~sI
where <PATH>
can be .
(show current directory, like pwd), *
(list files in current directory), a particular file path, etc.
因此,请使用短 (8.3) 名称。您可以使用 Windows(不是 MinGW)命令获取短名称,for %I in (<PATH>) do @echo %~sI
其中<PATH>
可以是.
(显示当前目录,如 pwd)、*
(列出当前目录中的文件)、特定文件路径等。
Btw, to copy from the awful cmd.exe window, click the icon in the upper-left corner of the title bar, go to Properties, Options, and enable QuickEdit Mode. Then you can select text with your mouse. The Enter key (or menu>Edit>Copy) copies the text to the clipboard. The insert key (or menu>Edit>Paste) pastes it.
顺便说一句,要从糟糕的 cmd.exe 窗口复制,请单击标题栏左上角的图标,转到“属性”、“选项”,然后启用“快速编辑模式”。然后您可以用鼠标选择文本。Enter 键(或菜单>编辑>复制)将文本复制到剪贴板。插入键(或菜单>编辑>粘贴)粘贴它。
回答by zeta
Not sure if this helpful or not (in fear of being downvoted), but I created a semantic link in order to avoid paths with spaces. Not sure if it will solve the problem since in my scenario it displayed a different error after I used the semantic link relating to pthreads which I still haven't been able to fix.
不确定这是否有帮助(害怕被否决),但我创建了一个语义链接以避免带有空格的路径。不确定它是否会解决问题,因为在我的场景中,在我使用与 pthread 相关的语义链接后,它显示了一个不同的错误,但我仍然无法修复。
Creating semantic link using the command prompt:
使用命令提示符创建语义链接:
mklink /j "C:\newshortcut" "C:\Program Files\Directory with spaces"
Then on the command you want to run, you use C:\newshortcut
然后在要运行的命令上,使用C:\newshortcut
回答by Eddie Parker
Sorry for necroing this, but I had a similar problem and I was able to fix it using cygpath.
很抱歉使这个问题恶化,但我遇到了类似的问题,我能够使用 cygpath 修复它。
For my case I was trying to make an environment variable to visual studio:
就我而言,我试图为 Visual Studio 创建一个环境变量:
export DEVENV="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.com
echo $DEVENV
$DEVENV /build "Release|win64"
Which would result in:
这将导致:
/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.com
-bash: /c/Program: No such file or directory
The solution was to use cygpath -w to convert the path with spaces into an 8.3 filename:
解决方案是使用 cygpath -w 将带空格的路径转换为 8.3 文件名:
export DEVENV=$(cygpath -w -s "/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.com")
echo $DEVENV
$DEVENV /build "Release|win64"
Which results in:
结果是:
C:\PROGRA~2\MICROS~119\COMMUN~1\Common7\IDE\devenv.com
and no error. Hopefully this helps future travellers.
并且没有错误。希望这对未来的旅行者有所帮助。