Windows SDK 7.1 command prompt LNK1104 - winapi

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.

Related

Running MSVC 'cl.exe' from Git Bash (MINGW64)

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

Get Windows nmake version from command prompt?

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.

How do I make visual studio 2017 compiler, specifically cl.exe work with luarocks?

I tried to just find a lua rocks library made for lua 5.3 first of all so I come across mathx, I have no idea what this library really does I just wanted to test luarocks installation is working correctly. Everything seems to be working fine but what I believe now in windows by default it is currently looking for cl.exe, in visual studio 2017 I have this file located at:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe
However setting this directory in the path does not allow me to initiate the command in eithe command prompt of 'cl'
When installing from lua command prompt:
C:\Users\MYNAMEHERE>luarocks install lmathx Installing luarocks.org/lmathx-20150624-1.src.rock cl /nologo /MD /O2 -c -Folmathx.obj -IC:/lua/include lmathx.c 'cl' is not recognised as an internal or external command, operable program or batch file.
Error: Build error: Failed compiling object lmathx.obj
When installing from visual studio 2017 command prompt:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>luarocks install lmathx Installing luarocks.org/lmathx-20150624-1.src.rock cl /nologo /MD /O2 -c -Folmathx.obj -IC:/lua/include lmathx.c lmathx.c link -dll -def:mathx.def -out:mathx.dll C:/lua/lua53.dll lmathx.obj Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved.
C:\lua\lua53.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x430
Error: Build error: Failed compiling module mathx.dll
I think my macbook is doing similar but I will have to look at that another day so I am putting that aside for now.
The module I have tried to install above is: luarocks.org/modules/ignacio/lmathx
C:\Users\MYNAMEHERE>luarocks install luai Installing luarocks.org/luai-1.0-2.src.rock luai 1.0-2 is now installed in C:\lua\systree (license: MIT/X11)
I have managed to get one module installed: luarocks.org/modules/cschen1205/luai
which gave the following output in normal windows command prompt after typing: luarocks install luai
C:\Users\MYNAMEHERE>luarocks install luai Installing zluarocks.org/luai-1.0-2.src.rock luai 1.0-2 is now installed in C:\lua\systree (license: MIT/X11)
However I was struggling to get any lua code to test this even on there github for it.
I am left stumped overall either I can't get windows to pick up the visual studio 2017 compiler to build luarocks files (Please note I do have C:\MinGW installed as a portable version as well with c and c++ compiler in there of gcc but this is already set in path, I can use this instead if vs studio 2017 is to new to work but how to default lua rocks to mingw gcc rather than cl.exe to build libraries????) or something installs then I am struggling to find out how its installed (not from source, presumed though???)or sample code to check such a luarock has installed.

VCbuild not running with "accessing a corrupted shared library" under XP cygwin/x64

I am trying to run vcbuild in XP 64 bit and visual studio 2008. The problem is rather puzzling, both because it makes little sense, and because I know very little of windows.
I am actually going to run it from cygwin, but it's not relevant I think. The error message in the title is the one I get on cygwin, and it spawned further research.
I am running windows 64 bit, installed VS2008 (with x64) and updated all the bunch.
When I open a terminal, and I try to invoke vcbuild, I get this
C:\Documents and Settings\Administrator\Desktop>"C:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\bin\amd64\vcbuild.exe"
The system cannot execute the specified program.
There's another vcbuild that runs
C:\Documents and Settings\Administrator\Desktop>"C:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\vcpackages\vcbuild.exe"
Microsoft (R) Visual C++ Project Builder - Command Line Version 9.00.21022
Copyright (C) Microsoft Corporation. All rights reserved.
but as far as I understand it's 32 bit. I tried running dependency walker, and indeed it turns out that the first one is a 64 bit program (note the 64 bit icon), linking to 32 bit libs (???)
and the second one is a 32 bit program linking against 32 bit libs
I have no idea of what went wrong (or is wrong). I would say it is a variable definition problem. I tried calling vcvarsall.bat x64
C:\Documents and Settings\Administrator>"c:\Program Files (x86)\Microsoft Visual
Studio 9.0\VC\vcvarsall.bat" x64
Setting environment for using Microsoft Visual Studio 2008 Beta2 x64 tools.
but no luck. Any idea ?

Building Opensource Qt for Visual Studio 2005/2008

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.

Resources