I'm trying to find a way to invoke the Visual Studio C++ compiler (MSVC) from within my Git Bash terminal on Windows.
The Developer Command Prompt for VS2017 works fine, it's just annoying to switch between windows just to compile my application.
I tried adding cl.exe to my Path and was unsuccessful. Google keeps pointing me toward using GCC, which I'm not interested in doing. I was also able to find these two questions, both about Cygwin, one about invoking cl.exe and another about importing vcvars32.bat funcationality (They're linked to each other). The issue is that 1) these are for Cygwin, not MINGW64, and 2) point me to vcvars32.bat/VsDevCmd.bat. That script seems to mainly be for setting up the development environment (It also passes all smoke tests invoked by VsDevCmd.bat if that matters.).
So my question(s) is/are:
Is this possible?
How do I resolve bash: cl: command not found and allow calling cl.exe from Git Bash?
Simple workaround: launch your Git Bash terminal from inside a Developer Command Prompt terminal so that it inherits the environment.
Longer (but more flexible): Convert vcvars32.bat to a bash script and source it.
C:\>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.8
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\>f:\git\usr\bin\bash.exe
$ cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
Related
I am trying to build the source of CURA; (Link: https://github.com/Ultimaker/Cura/wiki/Running-Cura-from-Source-on-Windows). I followed the instructions but got error as below:
PS D:\work\cura-build-environment-master\build> nmake
Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop.
It looks like you may not have followed all of the instructions, such as this one in the Microsoft Visual Studio 2019 section:
When building files (using cmake or nmake) in the steps below be sure to use the 'VS2015 x64 Native Tools Command Prompt'. This ensures that the Visual Studio 2015 build tools are used.
I don't really know nmake, but I use nmake from "x64 Native Tools Command Prompt for VS 2017" under Windows 10; I would like to find out the version of this tool from the command prompt.
I have found this:
https://learn.microsoft.com/en-us/cpp/build/reference/batch-mode-rules?view=vs-2019
To check the NMAKE version, run the _NMAKE_VER macro available with NMAKE version 1.62 or higher. This macro returns a string representing the Visual C++ product version.
... but I don't really know how to "run the macro" - I tried this:
C:\>nmake _NMAKE_VER
Microsoft (R) Program Maintenance Utility Version 14.16.27026.1
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1073: don't know how to make '_NMAKE_VER'
Stop.
So, it dropped something like a version string, but there's still an error.
Thus, how can I get the nmake version from the command line properly?
As Hans Passant suggests, you could consider typing nmake/?; this will give you what you already know from your question, namely 14.16.27026.1.
The point of the variable _NMAKE_VER is to allow you to test the nmake version, or the Visual Studio version, from within the makefile. For example, suppose your makefile is:
# Check the first three characters of _NMAKE_VER to
# obtain the Visual Studio version:
!if [cmd /c if "%_NMAKE_VER:~0,3%"=="14." exit 1]
! message Using VS 2017, with NMAKE $(_NMAKE_VER)
!elseif [cmd /c if "%_NMAKE_VER:~0,3%"=="12." exit 1]
! message Using VS 2013, with NMAKE $(_NMAKE_VER)
!else
! message Unknown VS version, with NMAKE $(_NMAKE_VER)
!endif
# Just output _NMAKE_VER:
all:
#echo "Version NMAKE" $(_NMAKE_VER)
Then issuing the following command from the Visual Studio 2017 Developer Command Prompt:
nmake /nologo
will give (on my machine):
Using VS 2017, with NMAKE 14.10.25019.0
Version NMAKE 14.10.25019.0
or for Visual Studio 2013:
Using VS 2013, with NMAKE 12.00.21005.1
Version NMAKE 12.00.21005.1
We need to use the DOS cmd to inspect _NMAKE_VER, as nmake unlike gmake has limited string manipulation tools.
Edit: The above test will probably not be able to distinguish between VS 15 and VS 17, since the VS 17 nmake version number begins with 14 rather than the expected 15.
I'm trying to automate builds of Visual Studio 6 projects (written in C). I can build the project (.dsp) with the following command from the windows console:
msdev reg.dsp /make "reg - Win32 Release"
But I cannot do this from the GIT bash. What it does is just open the project in visual studio, and report a following error:
C:/Program Files/Git/make
File not found.
Please verify that the path and the file name are correct.
sh --version says the following:
GNU bash, version 3.1.0(1)-release (i686-pc-msys)
Copyright (C) 2005 Free Software Foundation, Inc.
So, how can I build a Visual Studio 6 C project in GIT Bash console?
I guess something weird happens when I send / (slash) parameters in git bash on windows. I replaced those with a - (dash/minus), so the build command looked like the following, and it finally worked:
msdev reg.dsp -make "reg - Win32 Release"
And within a shell script it look like this (in case someone finds this to be useful):
command="msdev ../reg.dsp -MAKE \"reg - Win32 Release\""
eval $command
I just installed Windows SDK 7.1 on Windows XP Professional with SP3. Now I'm checking to see if the installation is OK and, already, I'm having a problem. I still cannot get cl.exe compile a simple hello world C++ code from the Windows SDK 7.1 Command Prompt. Here is a snapshot of command prompt output:
Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows XP x86 Debug
C:\Program Files\Microsoft SDKs\Windows\v7.1>cd /d "D:\My Documents\Sources"
D:\My Documents\Sources>cl /EHsc /FeD:\Target\hello hello.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1104: cannot open file 'C:\Documents'
I tried moving hello.cpp to D:\ and ended up with the same result. CSC.exe, on the other hand, compiled a hello world C# code in the same command prompt without a hitch. What should I do now?
Note that I do not have any version of Visual Studio installed. I installed Windows SDK so that I can use Qt Framework 4.8.0 for VS2010 in Qt Creator and learn a little bit of C# in SharpDevelop.
Some people adviced me to wrap all environment variable values containing C:\Documents and Settings\ in double quotes, e.g.: Set ALLUSERSPROFILE="C:\Documents and Settings\All Users", Set USERPROFILE="C:\Documents and Settings\Ant Luc", and so forth. There was no sane way to perform the modification, except for %TEMP% and %TMP%, since they were not available for editing through System Properties > Advanced > Environment Variables. So I edited C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd and added the following lines right below #ECHO OFF:
SET ALLUSERSPROFILE="C:\Documents and Settings\All Users"
SET USERPROFILE="C:\Documents and Settings\Ant Luc"
SET HOMEPATH="C:\Documents and Settings\Ant Luc"
SET APPDATA="%USERPROFILE%\Application Data"
SET TEMP="%USERPROFILE%\Local Settings\Temp"
SET TMP="%USERPROFILE%\Local Settings\Temp"
But I then got Error C1083 when compiling the hello world code with cl.exe. In desperation, I edited C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd again, and changed the value for %TMP% to D:\VSTEMP, created a directory called VSTEMP in D:\, tried to compile the source code again, and sighed in relief because it finally compiled successfully.
I decided to grab and install Visual Studio 2010 Express out of curiosity, opened Visual Studio Command Prompt, tried to compile the same hello world code, and was faced with the same set of problems which I fixed with the same workaround. Conclusion: the compiler (or linker) cannot properly handle whitespace in %TMP% -- assign a directory without a single whitespace to it.
I still do not know what is wrong with my setup, but all this hassle seems stupid anyway. FWIW, this is the first toolchain that made me jump through hoops just to get a hello world code compile successfully.
Does anyone have instructions on building the opensource version of Qt? Now that the repository is opened up, I'm trying to build for VS2008 but I'm getting errors when it tries to build qmake.
I found the question I'm looking to use Visual Studio to write and compile using the open source version of Qt4 but this information is out of date, and doesn't really help me. For reference, here's what happens when I try to build with configure -platform win32-msvc2008
Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
cl -c -Foproject.obj -W3 -nologo -O2 -I. -Igenerators -Igenerators\unix -Igenerators\win32 -Igenerators\mac -
IC:\dev\open_source\qt\include -IC:\dev\open_source\qt\include\QtCore -IC:\dev\open_source\qt\include -IC:\dev\open_sou
rce\qt\include\QtCore -IC:\dev\open_source\qt\src\corelib\global -IC:\dev\open_source\qt\include\QtScript -IC:\dev\op
en_source\qt\mkspecs\win32-msvc2008 -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL
-DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -D
QT_NO_DATASTREAM -DQT_NO_PCRE -DQT_BOOTSTRAPPED -DQMAKE_OPENSOURCE_EDITION project.cpp
project.cpp
c:\dev\open_source\qt\src\corelib\tools\qstringlist.h(45) : fatal error C1083: Cannot open include file: 'QtCore/qalgori
thms.h': No such file or directory
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
Building qmake failed, return code 2
Well, one helpful thing is to run configure inside the Visual Studio Command Prompt. That should be available in the Visual Studio start menu group under Visual Studio Tools.
Also now when you run configure you don't have to specify target platform, because it will be set as an environment variable by the VS Command Prompt.
I got errors from configure and nmake when I did not use the VS Command Prompt, and since switching I have not had any issues.
So the simple instructions would be:
1) open VS command prompt
2) navigate to qt folder where configure.exe is located
3) configure
4) nmake
Please, ensure that you have ActiveState Perl installed
This blog article seems to have more recent information on building Qt with visual studio. Hope it helps.
Note that Nokia, as of Qt 4.6, is now providing their own open source VS builds of Qt, so it is no longer necessary to build from source yourself to do development with Visual Studio. Access their open source download page, and look for builds named (e.g.) qt-win-opensource-4.6.1-vs2008.exe.
Also, if you simply want to compile with MSVC so you can develop with the open source libraries with visual studio, I put together a project to provide "pre-built" Qt LGPL libraries with MSVC 2008.
It might be helpfull and has the advantages of taking up less space then compiling it yourself. It also provides a command prompt with all your environment variables set up for you and a link to launch Visual Studio with a Qt environment. It's called qt-msvc-installer.
What user156973 said. Install ActiveState perl and run configure again.