mingw make can't handle spaces in path? - windows

I am trying to compile code, the makefile created using qmake.
When I run mingw32-make I get the following error:
cd bzip2-1.0.5\ && c:\QtSDK\Desktop\Qt\4.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?

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.
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.
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.

From the MinGW "Getting Started" guide:
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.
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 may work but Windows is sometimes not as logical as UNIX-based shells in this area.
Spaces in file names are evil anyway :-)

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.
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

Sorry for necroing this, but I had a similar problem and I was able to fix it using cygpath.
For my case I was trying to make an environment variable to visual studio:
export DEVENV="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.com
echo $DEVENV
$DEVENV $1 /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:
export DEVENV=$(cygpath -w -s "/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.com")
echo $DEVENV
$DEVENV $1 /build "Release|win64"
Which results in:
C:\PROGRA~2\MICROS~1\2019\COMMUN~1\Common7\IDE\devenv.com
and no error. Hopefully this helps future travellers.

Related

How do you match an exact file extension under Windows/command line/file open dialog?

I am trying to get a directory listing of only files with a given extension. At first blush this seems to be a simple thing to do, however check out this simple example:
C:\CODE\metcal>dir /b *.exe
metcal.exe
metcal.exe1
Notice that this returns metcal.**exe** and metcal.**exe1** as matches.
With python files a similar thing happens:
C:\CODE\metcal>dir /b *.py
metcal.py
metcal.pyc
Notice again Windows has determined that *.py takes anything that starts with *.py so it captures the .pyc files as well.
Is there a way to get only the extensions that match exactly? In the above python files example I would like the following to occur (obviously with the correct syntax substituted for *.py)
C:\CODE\metcal>dir /b *.py
metcal.py
As a note the matching under Windows not as simple as it seems.
*.exe matches foo.exe, foo.exe1, foo.exeabcde but not foo.exe.bak
There are other questions on SO that are similar that are related to long/short file names. The *.py and *.pyc example here should not introduce name mangling machinery.
**I have experimented on XP and Win7 machines and this behavior is not consistent at the cmd Prompt and file open dialogs. This inconsistant behavior makes me suspect this problem is related to settings of somekind. **
It's because windows wildcards on extensions check both long and short names as explained in this answer:
https://superuser.com/questions/238900/winxp-dir-command-3-and-4-char-extensions-are-the-same#238930
Solution there is to disable 8.3 names creation and then striping them on ntfs volumes which will also improve performance.
Microsoft Docs: Fsutil 8dot3name
Remarks:
Permanently removing 8dot3 file names and not modifying registry keys that point to the 8dot3 file names may lead to unexpected application failures, including the inability to uninstall an application. It is recommended you first back up your directory or volume before you attempt to remove 8dot3 file names.
So if you want to get only those extensions (.py and .pyc), you should try like this way :
#echo off
dir /b *.py*
pause
You can use the Unix ls command from the Windows Subsystem for Linux to do this, assuming you have WSL installed. It's freely available from Microsoft. From your Windows command prompt, type wsl followed by the ls command to list the files you want.
So, for your example, wsl ls metcal.py returns only metcal.py. To get the same results as you're seeing with dir, use wsl ls metcal.py*.

add a shortcut in Windows Git Bash (MinGW) for Visual Studio Code

I am looking for a way to add shortcuts in Windows Git Bash (MinGW).
$ code . // should open code in current location
The Visual Studio Code setup page shows how to setup shortcuts in Mac OS X / Linux.
I just need a way to setup a basic shortcut so when I type
code c:\
it will execute:
"c:\Program Files (x86)\Microsoft VS Code\bin\code.cmd" c:\
I got it to work using node:
node /c/Program\ Files\ \(x86\)/Microsoft\ VS\ Code/bin/code.js .
Now I just need to make this into a shortcut.
I think this could be accomplished using a symlink. I'm just not sure how to add an extra variable in there i.e.
ln -s "node /c/path/to/code.js" code
Doing something like the above fails since adding a string is not recognized as valid path.
solution
to expand on zoon's answer the following worked for me
create a code.cmd file with the following contents
#! /bin/sh
node /c/Program\ Files\ \(x86\)/Microsoft\ VS\ Code/bin/code.js $*
add a symlink to that code.cmd
ln /c/path/to/file/code.cmd code
this allows me to pass path parameter to code
code ./somefolder/
Create a shell script:
#! /bin/sh
cmd //C code.cmd $*
name it 'code' and put it with 'code.cmd'.

How to add directories to Cygwin gcc default search path

I'm a bit of a noob at working with compilers. I want to add an arbitrary directory on my win 8 C:\ drive to the Cygwin gcc default search path.
Here is what I have tried so far. Using gcc --help I found the commands -print-search-dirs and -B <directory> ("add directory to the compiler's search path").
Using the former command output this:
install: /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/
programs: =/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/:/usr/lib/gcc/x86_64-pc-cygwin/4.
9.2/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/:/usr/li
b/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-p
c-cygwin/bin/x86_64-pc-cygwin/4.9.2/:/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../.
./../x86_64-pc-cygwin/bin/
libraries: =/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/:/usr/lib/gcc/x86_64-pc-cygwin/4
.9.2/../../../../x86_64-pc-cygwin/lib/x86_64-pc-cygwin/4.9.2/:/usr/lib/gcc/x86_6
4-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/lib/../lib/:/usr/lib/gcc/x86_64-p
c-cygwin/4.9.2/../../../x86_64-pc-cygwin/4.9.2/:/usr/lib/gcc/x86_64-pc-cygwin/4.
9.2/../../../../lib/:/lib/x86_64-pc-cygwin/4.9.2/:/lib/../lib/:/usr/lib/x86_64-p
c-cygwin/4.9.2/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../..
/x86_64-pc-cygwin/lib/:/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../:/lib/:/usr/
lib/
The full path to /usr is C:\cygwin64\usr. The directory I want to add is c:\directory So I tried gcc -B /../directory and other variations, but I get error
gcc: fatal error: no input files
compilation terminated
Seems like it thinks I'm trying to compile something. I want to permanently add a directory to the list of default search paths.
There are two issues at play here.
The first problem has to do with the fact that Cygwin views the top of its directory tree / to be within the Windows directory C:\cygwin64. As a result, you are unable to move above that point in the filesystem. The solution is to go through Cygwin's directory /cygdrive, which is the access point where all Windows disk drives are mounted. You can access the top-level Windows directory C:\ from Cygwin as /cygdrive/c. So for the problem above, instead of using gcc -B /../directory, try using gcc -B /cygdrive/c/directory.
The second issue is that of adding directories to the search path, versus telling it to compile a specific source file. Given the date of this question, I assume you've solved that part of the problem at this point?

Spaces in Cygwin/bash aliases?

I am attempting to set up aliases for my Cygwin bash shells, to run programs contained in the standard Windows C:\Program Files subdirectories. Unfortunately, the alias command really doesn't like spaces in a directory name, and nothing I've tried seems to work. I'm trying to get the following running:
alias npp='/cygdrive/c/Program Files/Notepad++/notepad++.exe'
I am currently cheating and using a soft link, but I would prefer to use an alias.
Escape Characters:
alias npp="/cygdrive/c/Program\ Files/Notepad++/notepad++.exe"
Edit: Note the change from single to double quotes as well.
While the answer above will solve the problem, here is another thing you can try:
Use junction utility from microsoft to create a symlink "C:\ProgramFiles" to "C:\Program Files" (and "C:\ProgramFiles86" to "C:\Program Files (x86)")
Sample usage:
C:\>junction C:\ProgramFiles "C:\Program Files"
Amusingly, the link I gave above mentions the exact same case of "Program Files" having a space in it.

Makefile not working with cygwin

I just installed cygwin with C++ compiler and Perl on my windows machine. Whenever
trying to compile the C++ files with the makefile I get the following error:
>make
Cant find C:\Program on PATH
Not sure what path is exactly missing and where I can change it...
You should install cygwin in C:\, not in C:\Program Files\ - the latter often causes problems because of the space, as is the case here.
You've got a space in your PATH environment variable. Wherever you set the path, you might use an 8.3 filename instead of an extended filename, or you might encapsulate the section with spaces in quotes. For example: PATH=c:\windows;"c:\program files\foo"

Resources