Unexplained makefile behavior - windows

I have the following makefile:
all:
echo $(PATH)
When I execute the file using the following command
make -f pathtest.mk
I get both an error and correct execution. The error is listed bellow
/usr/bin/sh: -c: line 0: syntax error near unexpected token `('
/usr/bin/sh: -c: line 0: `echo C:\Users\Aris\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Aris\bin;C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files\PuTTY;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe;C:\Program Files\dotnet;C:\Program Files (x86)\VisioForge\VisioForge .Net SDKs Base Redist x86;C:\Program Files\VisioForge\VisioForge .Net SDKs Base Redist x64;C:\Program Files (x86)\VisioForge\VisioForge .Net SDKs FFMPEG EXE x86 Redist;C:\Program Files (x86)\VisioForge\VisioForge .Net SDKs LAV Redist x86;C:\Program Files\Pandoc;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\dotnet;C:\Users\Aris\AppData\Local\Microsoft\WindowsApps;C:\Users\Aris\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Aris\MiKTeX\miktex\bin\x64;C:\Users\Aris\.dotnet\tools;C:\Users\Aris\bin\pmtk;C:\Users\Aris\AppData\Roaming\npm;C:\Neovim\bin;C:\Users\Aris\bin\mingw64\bin;C:\Users\Aris\bin\netcoredbg;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl'
mingw32-make: *** [pathtest.mk:2: all] Error 1
the all target has tab identation and i have tried the file in both unix and dos line endings. I don't know what is happening. I am under a git for windows environment and I
am using the mingw make. I am trying to do this test since I am trying to compile some GNU code on my windows machine.

make expands the $PATH and lets your shell run the echo ... line. But ; and ( are special characters in the shell that cause the errors.
If you are sure there are no double quotes in the $PATH, you can use
echo "$(PATH)"
or similarly with single quotes.

Related

How can I use the cl command on PowerShell?

I am unable to use the cl command in PowerShell.
I tried to add the following command to my PowerShell profile to exec vcbuildtools.bat, but PowerShell does not recognize cl command on PowerShell?
&"C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
OS: Windows 10
Just to be clear I'm addressing the asker's issue that cl is not in the PATH even after running this in PowerShell
&"C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
I think this boils down to the issue that batch file can't export variables to PowerShell (also related: this question), as you've found out with vcbuildtools.bat. I think it's because PowerShell invokes a cmd.exe subshell to execute the batch file which changes the environment in the subshell but the changes don't propagate to the parent shell i.e. PowerShell.
Solution 1
One way is to use the fact that subshell inherits the environment from the parent shell. So if you run this in PowerShell, the environment set by the batch file is preserved
cmd.exe /k "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" `& powershell
Take note of `&. The character has to be escaped because it has a special meaning in PowerShell.
Solution 2
The Pscx module has an Import-VisualStudioVars function which imports environment variables for Visual Studio. An example usage is
Import-VisualStudioVars 2015 amd64
if you're using VS/BuildTools 2015 and compiling 64-bit programs. You can use Pop-EnvironmentBlock to revert the changes. See man Import-VisualStudioVars -full for more information.
Alternatively, Pscx also has an Invoke-BatchFile function that retains environment changes by a batch file. An example usage
Invoke-BatchFile "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
See man Invoke-Batchfile -full for more information.
Notes
To download the up-to-date version of Pscx from PowerShell gallery, you will need PowerShellGet which is shipped with PowerShell 5 and is available as a downloadable installer for PowerShell 3 and 4.
For those with PowerShell 1 and 2, older versions of Pscx is available on Codeplex.
You can use the following function to invoke a cmd.exe shell script (batch file) and persist its environment variables:
function Invoke-CmdScript {
param(
[String] $scriptName
)
$cmdLine = """$scriptName"" $args & set"
& $env:SystemRoot\system32\cmd.exe /c $cmdLine |
Select-String '^([^=]*)=(.*)$' | ForEach-Object {
$varName = $_.Matches[0].Groups[1].Value
$varValue = $_.Matches[0].Groups[2].Value
Set-Item Env:$varName $varValue
}
}
Add this function to your PowerShell profile, and run the batch file using the function:
Invoke-CmdScript "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat"
Fortunately, VS 2019 Community now has a Developer PowerShell for VS 2019 command.
The actual command, if you want to see the properties for the shortcut, is rather verbose.
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 14bbfab9}"
Anyway, I am using this and it adds the right cl.exe to my path, but there is an odd message after running it:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\ostream(750): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
.\hey.cpp(4): note: see reference to function template instantiation 'std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const char *)' being compiled
Another option from PowerShell gallery:
posh-vs
Makes Visual Studio command line tools available in PowerShell. Supports Visual Studio 2017 and 2015.
I also encountered the same problem, type cmd.exe and you'll change control to command line.
PowerShell example
If you want to go back to PowerShell, no problem. Just write exit. As simple as it sounds

Error when converting batch file to shell script and executing TFS commands

I have a batch file that executes these commands:
set repodir=D:\Folder
cd /d %repodir%
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
tf undo * /recursive /noprompt
tf get
I want to achieve same functionality from shell script. I am able to change the directory path to wherever code is present
Problems:
command call is not found - read that I need to use . operator in shell script. Tried this but not working. Error is "#echo command not found" in vcvarsall.bat ( the first line in that file is #echo off )
. "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
Since calling batch file is failing in step 2, command tf is not found
tf undo * /recursive /noprompt
tf get
Environment: I am trying to run the shell script using cygwin on Windows Server 2008
Remove the 'call' because that is for calling one bat file from another.
Specify the full path for tf.exe. Of course that will vary depending on the version of TFS you have installed.

'C:\Program' is not recognized error

I've recently tried changing my environment variables to set paths to javac.exe (among other things). It was working fine until, all of a sudden, I started getting this error. For example, I declared a JAVA_HOME variable to be
C:\Program Files\Java\jdk1.7.0_25
After which, I add
%JAVA_HOME%\bin
to the PATH variable, but this gives me an error:
'C:\Program' is not recognized as an internal or external command, operable command or batch file.
This error makes it seem like it's running into problems with the space in "Program Files". This is weird, though, since it wasn't doing this for a good while, then started. Further, there are other variables with spaces in them that work just fine. I've tried deleting the variable and recreating it, putting quotes around JAVA_HOME (which goes to the correct path, but does not find javac.exe correctly)..
Any tips on what I might do?
This is on Windows 7.
EDIT:
The environment variables were set by going Control Panel > Advanced System Settings > Environment Variables. The value of the variables were set by copying the address of the folder I want through an Explorer window. I added it to the PATH environment variable by appending the address with a space between the preceding variable and a semicolon at the end, as such:
C:\Users\Demo_User_1\AppData\Roaming\npm; %JAVA_HOME%
where the JAVA_HOME variable is defined as such:
C:\Program Files\Java\jdk1.7.0_25
I test the value of the variable through a command prompt by typing %JAVA_HOME%, and that's where I get the resulting error of "'C:\Program' is not recognized..."
The results of 'set' are as follows:
C:\Users\Demo_User_1>set
ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_64-2013
0717\sdk
APPDATA=C:\Users\Demo_User_1\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DEMO_USER_1-HP
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Demo_User_1
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
LOCALAPPDATA=C:\Users\Demo_User_1\AppData\Local
LOGONSERVER=\\DEMO_USER_1-HP
NUMBER_OF_PROCESSORS=4
OnlineServices=Online Services
OS=Windows_NT
Path=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Clien
t\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
(x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\
x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\I
ntel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Managem
ent Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engin
e Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compone
nts\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\Wir
elessCommon\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files
(x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows
Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\
Tools\Binn\;C:\Program Files\nodejs\; C:\Users\Demo_User_1\Desktop\Android\adt-b
undle-windows-x86_64-20130717\sdk/platform-tools; C:\Users\Demo_User_1\Desktop\A
ndroid\adt-bundle-windows-x86_64-20130717\sdk\tools; %JAVA_HOME%; %ANT_HOME%/bin
; C:\Program Files\Java\jdk1.7.0_25\bin; C:\Users\Demo_User_1\AppData\Roaming\np
m; "%JAVA_HOME%"; ;C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_6
4-20130717\sdk/tools; C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x8
6_64-20130717\sdk/platform-tools
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PCBRAND=Pavilion
Platform=MCD
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3a09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\DEMO_U~1\AppData\Local\Temp
TMP=C:\Users\DEMO_U~1\AppData\Local\Temp
USERDOMAIN=Demo_User_1-HP
USERNAME=Demo_User_1
USERPROFILE=C:\Users\Demo_User_1
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools
\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
Yet another solution is to do this: C:\Program Files has a short name
C:\Progra~1
in windows.
so simply write Progra~1 instead of the Program Files. {added missing 'r'}
Okay, that makes it clearer.
There are two main problems here.
First of all, the reason you're getting 'C:\Program' is not recognized... is, of course, because it contains spaces. The fact that you have it quoted in the PATH environment variable has no relation to how %JAVA_HOME% is interpreted at the prompt. You have two options.
Quote it when you define the variable, i.e. set JAVA_HOME to "C:\Program Files\Java\jdk1.7.0_25"
Quote it when you invoke it. Type "%JAVA_HOME%\bin" at the prompt. Of course, you'll get the "not recognized as an internal or external command, operable program or batch file" error unless you end the path with an executable (e.g. "%JAVA_HOME%\bin\javac.exe"), but you'll see that this way it complains about '"C:\Program Files\Java\jdk1.7.0_25"' rather than 'C:\Program'.
Second, you can't use environment variables in the path. You can use environment variables when you set the path at the command prompt. For example,
set PATH=%PATH%;%JAVA_HOME%
will work, but that's because %JAVA_HOME% is expanded at the command line and PATH is set to the result. If you check the value of PATH, you'll see that it ends with C:\Program Files\Java\jdk1.7.0_25, not %JAVA_HOME%.
Also, if javac.exe is in the bin subdirectory, you'll need to include that in the path, i.e. add ;C:\Program Files\Java\jdk1.7.0_25\bin to the path.
(BTW, you have %JAVA_HOME% in the path twice, and there's an extra semicolon after the second one.)
Is the path you are setting the JAVA_HOME environment variable in a user variable or a system variable? You cannot use user variables within system variables. So if JAVA_HOME is defined as a user variable and you are adding it to your system path that won't work.
From the output of your set command it looks like %JAVA_HOME% is not being resolved. It should show the expanded version not the one with % signs in.
Add a Path user variable and add %JAVA_HOME%\bin to that. Windows will add your user path to the end of the system path.
You should not need quotes in the JAVA_HOME variable even if it contains spaces.
Even though Adi Inbar is pretty clear on the problem, I think his workaround isn't the best solution, because it tries to patch around the original problem: spaces in the path of your JDK installation.
The best way to solve your problem is actually reinstalling JDK to a space-less path. All other workarounds will cause you headaches in the long run.
just add cd before adding the location
eg:
instead of
C:\Program Files\Java\jdk1.7.0_25
use
cd C:\Program Files\Java\jdk1.7.0_25
this helped me.
It is very clear that , this is caused due to the blank space. Just add quotes to the phrase it foldername which contains a blank space
C:\"Program Files"\Java\jdk1.7.0_25
if you are Windows 10, Use Browse Folder rather than Edit text. I had similar issue and this got resolved using above method.
Hope this helps!
Reinstall Java and change its installation directory from C:\Program Files\Java\jdk to somewhere in C:\Java\jdk. Avoid to use Program Files folder in installation as space between 'Program' and 'Files' creates problem.
Thanks!!

Why does quote location matter in running devenv.com from the windows command line?

I've been putting together a batch script (windows command line), and noticed some strange behavior with quoting paths containing spaces.
To reference locations with spaces (eg c:\Program Files), quotes must be used ("c:\Program Files"). For example, calling MSTest.exe, you would use:
"c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
If you were going to also reference other programs in that location, you might do something like:
set VSDIR="c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
%VSDIR%\MSTest.exe
The expanded call to MSTest.exe would look like this:
"c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"\MSTest.exe
This works as expected. The quotes are stripped, and the system loads MSTest.exe. Great. Now, if I do the same thing for devenv.com:
set VSDIR="c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
%VSDIR%\devenv.com
The system silently does nothing. No output is sent to standard out or error, and the error level remains at zero. Moving the quote after devenv.com loads the process as normal.
Anyone know why I'd see this behavior? Is it because devenv.com runs in real mode, or is it something about the process itself?

Make error -- how can I fix this?

I have many C files and I have built it by Visual Studio 2005 by commandline using a makefile.
All the object files are produced correctly and the linking process also works, but the final *.exe is not produced. At the last line, there is the error below. I understand nothing. Can anybody help me?
Here is the error:
process_begin: CreateProcess((null), /link /nologo /subsystem:console /o uartsim.exe xtmpmain.obj ua
rtsim.obj fiber_driver.obj xtmp_options.obj getopt.obj D:\usr\xtensa\XtDevToolsDE\install\tools\RB-2
008.4-win32\XtensaTools\lib\iss\xtmp.lib, ...) failed.
make (e=2): The system cannot find the file specified.
make.exe: *** [uartsim.exe] Error 2
Make can not find the uartsim.exe file. Either it's not on your computer, or it's not in your PATH.
Try to locate the file, check how the file path is passed to Visual Studio (environment variable, absolute path, just the executable name). If it's just the executable name, it means that you must have it in your PATH already to make it work.

Resources