How do I load the 64-bit Visual Studio Tools Command Prompt? - visual-studio-2010

My development machine is running Windows 7 Ultimate x64. I installed Visual Studio 2010 Ultimate. When I open the Visual Studio Command Prompt (2010), I get the message
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
I have also setup the PowerShell Community Extensions in my Windows PowerShell user profile. And I use the Invoke-BatchFile cmdlet to install the Visual Studio Tools into all my PowerShell sessions
$vcargs = ?: {$Pscx:Is64BitProcess} {'amd64'} {'x86'}
$vcvars = "${env:VS100COMNTOOLS}..\..\VC\vcvarsall.bat"
Invoke-BatchFile $vcvars $vcargs
My vcargs resolves to amd64. I looked in the vcvarsall.bat file for the location of the x64 batch file and got ~dp0bin\amd64\vcvars64.bat. That directory (and file) does not exist.
How do I get the vcvars64.bat file installed properly?

When running in the batch processor, %~dp0 expands to the path where the .bat file is executing. So in the default install for VS2010, that resolves to c:\program files\microsoft visual studio 10.0\vc\bin\amd64\vcvars64.bat. Which is indeed missing, that's a bug they don't seem to be interesting in fixing.
Use "x86_amd64" instead. You'll get the cross compiler, the same one that's used by the IDE.

Install the x64 Components
The problem is an incomplete installation of Visual Studio. I only installed the C# components. I needed to install, at least, the Visual C++ x64 Compilers and Tools.
Adding Components to an Existing Installation
I had problems adding those components to an existing installation. VS2010, especially with SP1 installed, has a ton of bugs around modifying the installation. I encountered some kind of path not found error
I uninstalled SP1 first. I needed the VS2010 installation media on hand (unpack to a directory, insert the real disc, or mount to a virtual drive).
Then I added the VC++ components to the VS installation
Then I was able to reinstall SP1.

I've run into roughly the same problem a number of times. It appears that the structure MS has set up for this is so fragile that installing or removing any software on the same machine (or, apparently, breathing anywhere near that machine) can and will break it. Worse, they have a nearly impenetrable web of batch files invoking each other, that in the end carry out some fairly trivial tasks in what appears to be nearly the most roundabout way possible.
Although I suppose it wastes a bit of memory I decided to simplify my life a bit, and use this:
#include <windows.h>
#include <iostream>
#include <string>
#include <process.h>
void setenv(std::string const &name, std::string const &value) {
SetEnvironmentVariable(name.c_str(), value.c_str());
}
std::string vs_base = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\";
std::string vc_base = vs_base + "VC\\";
std::string sdk_dir = "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\";
int main(int argc, char **argv) {
char inc_name[] = "INCLUDE";
char lib_name[] = "LIB";
char path_name[] = "PATH";
std::string inc_dir = getenv(inc_name);
std::string lib_dir = getenv(lib_name);
std::string path_dir = getenv(path_name);
inc_dir = vc_base + "include;" + sdk_dir + "include;" + inc_dir;
lib_dir = vc_base + "lib;" + sdk_dir + "lib;" + lib_dir;
path_dir = vc_base + "bin;" + sdk_dir + "bin;" + vs_base + "Common7\\IDE;" + path_dir;
setenv(inc_name, inc_dir);
setenv(lib_name, lib_dir);
setenv(path_name, path_dir);
char path[MAX_PATH];
GetSystemDirectory(path, sizeof(path));
strcat(path, "\\cmd.exe");
_spawnlp(_P_WAIT, path, path, NULL);
return 0;
}
You'll have to adjust the base directories at the top for the locations where you have things installed. One of these days I suppose I should rewrite this to use a separate configuration file (I've pretty much worked out an XML format that should work reasonably well), but this has worked well enough that I haven't bothered to finish that, and since it's for a programmer anyway, doing a trivial modification and re-compile isn't particularly onerous.

I had the problem, where I had visual studio 2010 professional (i'm guessing not SP1, it says "Version 10.0.30319.1 RTMRel" in About), and I also had the problem where in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC folder, it had vcvarsall.bat, but all of the paths that it tried to find any of the other .bat files were invalid, aka I had no other bat files.
I came across this forum post and it was the only thing that solved my problem.
Some people here were also saying "just use SetEnv" but i didn't know where it was because it wasn't in my PATH (typing setenv resulted in 'command not found'), so this is a more complete answer, that i'm posting here so people don't have to struggle like I did for so long
Posting here for archival purposes:
The batch file to set the environment parameters to compile for 64 bit
is contained in the Windows SDK.
After installing the Windows SDK use the following call CALL
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
Or create file C:\Program Files (x86)\Microsoft Visual Studio
10.0\vc\bin\amd64\vcvars64bat with the line above.

Do you have the Microsoft Windows SDK 7.1?
Open your ordinary Visual Studio Command Prompt and type:
setenv /x64
If your 64bit compilers are missing, you might need to read KB2519277.

Related

Visual Studio Exe App compilation path change

I just want to change the exe file Visual Studio compilation path change
I am doing it like this now. i created a bat file that copied file. I have added visual studio build events. I wonder if there is an easier way.
meanwhile the exe file is being copied to the network drive
I had this problem in a different context (Elixir/Phoenix, Rust), but the root cause was the same: cl.exe could not be found during compilation.
My setup was:
Windows 10, x64
Visual Studio Community 2017 already installed, but only for C# development
For some reason the solution with installing the Visual C++ Build Tools (as #cozzamara suggested) did not work. Stops during installation with some obscure error message. Guess it did not liked my existing Visual Studio installation.
This is how I solved it:
Start up the Visual Studio Installer
Check the Desktop development with C++ (screenshots here)
Execute following command before compiling:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
From this on the command cl.exe works. Alternatively (and more conveniently for development) start the application 'Developer Command Prompt for VS 2017' or 'x64 Native Tools Command Prompt VS 2017'.
Share
I solved the problem by writing code like this in the Post build field, I just ensured that the exe was copied to the field I wanted
COPY $(TargetPath) "\x.x.x.x\ortak\yakup\TestApp.exe"
pause
$(TargetPath) = It gives the location where the exe exited, along with the exe name
"C:\yakup\project\TestApp.exe" like

How to Install the Visual C++ Redist Using NSIS

My C++ application needs to install the Visual Studio C++ redistributable. I'm using Visual Studio 2019 Community edition. I use NSIS (version 3.04) to create my install program. Should I try to detect if the redist is installed and only install it if it is not up to date?
There are a melange of answers about how to do this, including many methods of how to detect if the redist is installed. I'm not going to say that all of them are incomplete and don't work in a future proof method, but I have not had success with them. So, I think the best thing to do is just install the redist always and let Microsoft take care of it. As of March 2020 this will add 14MB to your installer program, but maybe in this age of high speed Internet that isn't the big deal it once was. Luckily this is quite simple, and hopefully this question will keep you from following all the dated references and links that I did.
Instructions on the redist from Microsoft can be found here: Redistributing Visual C++ Files
To turn this into NSIS:
Find the file you want to redistribute in your Visual Studio install. For me this is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\14.25.28508\vcredist_x86.exe
The version number is definitely subject to change (14.25.28508) in the future, likely just when you install updates to Visual Studio, so remember that you'll need to update that path when your install program breaks. You'll also need to choose between vcredist_x86.exe and vcredist_x64.exe depending on whether your build your application as 32-bit or 64-bit.
Add a section like this to your NSIS install file, probably before you do the main installation. All it does is copy the redist file into the filesystem, run it, wait for completion, then delete the redist file.
Section "Visual Studio Runtime"
SetOutPath "$INSTDIR"
File "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\14.25.28508\vcredist_x86.exe"
ExecWait "$INSTDIR\vcredist_x86.exe"
Delete "$INSTDIR\vcredist_x86.exe"
SectionEnd
Substitute the proper path for the redist file you want to use.
As written (and current redist program behavior), this will pop up a dialog that the user will have to follow through to install the redist. You can substitute quiet mode:
ExecWait '"$INSTDIR\vcredist_x86.exe" /quiet'
However I did not have good results with that. YMMV.
to get the additional switches to work you include them within the quotes.
so the above ExecWait command would be the following:
ExecWait "$INSTDIR\vcredist_x86.exe /install /quiet"
I am using this currently, however with the "/quiet" switch the actual NSI installer progress hangs until redist is installed.
Using "/passive" instead will give a progress report on the redist installation
I agree with gdunbar that detection methods are both complex and not so reliable, good summary of such methods is in this thread: Detect if Visual C++ Redistributable for Visual Studio 2012 is installed
However I didn't want to always include the VC redist in the installer, as it significantly increase installer size (e.g. VC++ 2019 redistributable is 24Mb, while my installer without it was 1Mb). So I ended up using what I think is quite reliable method of trying to run the executable, and downloading installer on the fly if needed. Below the details for VC++ 2019 redistributable:
Create console windows app, e.g. Visual Studio 2019 wizard create this code:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
The size of this app is 12K (compiled with "Favor small size" option).
Using the following code in NSIS to run it and download the installer if needed:
InitPluginsDir
;the hello word console app
;need to use nsExec plugin to prevent error popup (if redist is missing)
File /oname=$PLUGINSDIR\checkRedist.exe checkRedist.exe
nsExec::Exec '"$PLUGINSDIR\checkRedist.exe"'
Pop $0
${If} $0 != 0
DetailPrint "VC++ Redistributable package is missing!"
inetc::get "https://aka.ms/vs/16/release/vc_redist.x64.exe" $PLUGINSDIR\vcredist.exe
DetailPrint "Installing Visual Studio Redistributable package..."
ExecWait '"$PLUGINSDIR\vcredist.exe" /q /norestart'
DetailPrint "Done"
${Else}
DetailPrint "VC++ Redistributable already installed"
${EndIf}

How to generate vcvarsall.bat

My visual Studio 2015 installed without vcvarsall.bat.
This is not about how to find this file and I am also not a python developer.
MSDN states at the bottom of this page:
The vcvarsall.bat file can vary from computer to computer. Do not
replace a missing or damaged vcvarsall.bat file by using a file from
another computer. Rerun Visual Studio Setup to replace the missing
file.
I am running the installation through our local IT department so I only get a fixed version of the setup. It looks like this setup does not install the batch file.
I wonder what other means of generating this "file" (actually it is several files and a folder structure) there are - how does the visual studio setup generate this file and is that generation possible without running the whole setup?
You have some option to "install" vcvarsall.bat.
The obvious to rerun VS setup and add c++ features (maybe your IT dep is kind enough and...)
Install visual c++ build tools
Install windows sdk (select c++ related components)

VC++ cl.exe -- DLL not found

I added the bin directory of the VS2010 (not SP1) C++ compiler to my PATH variable on Windows XP. When i try to run it, it tells me that a DLL was not found.
I added this line to my PATH:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin;
Update: it still fails when I cd to the bin directory above, and then run the compiler
Can you help me out?
Run the VS command prompt shortcut or the batch file it points to, such as:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
to set up an appropriate environment including the path.
By the way, mspdb100.dll lives in C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE. But run the shortcut/batch file anyway - it does more than set up the correct path.
add Microsoft Visual Studio 10.0\Common7\IDE to your Path variable, than close cmd prompt and open it. now it will work.
Running the VS command prompt takes care of setting up the environment. Also, ensure that you are running the command prompt as an admin.
Installing Visual Studio 2010 SP1 C++ Compiler Setup fixed this issue for me. Visual Studio 2010 SP1 C++ Compiler install
I faced the same issue when I tried to run a 32 bit exe I built, on a 64 bit machine.
"mspdb100.dll couldn't be found by cl.exe "
Visual Studio 2010(the version I currently use) builds a 32 bit exe by Default.To create a 64 bit executable, just change the setting from Win32 to x64 in the dropdown box at the top of VS and build.This will build for you a 64 bit executable and solve your problem.

Generating DLLs from an MC file?

I am taking over a bit of a legacy project, and having issues getting it to install in Windows 7.
The project is coded in VB, and our IDE for it is Visual Studio 2005 with VSS (fun I know). It was originally created for XP. The original dev is around to coordinate with, but is off the maintaince team for this project, and admits that the code is quite poorly formatted and commented it was his first large project.
The project runs fine when I generate a debug or release build in Visual Studio 2005, and I can run it on the Windows 7 machine that built it just fine. However, the MSI that I generate to install with fails when run on Windows 7.
It looks to be an issue where the DLLs that are packaged with the project are not correct for Windows 7, but they were generated via an MC file. I have the source MC files, so attempted to use MS's mc.exe tool and its counterparts to create the dll, but am not seeing any output.
The only walkthroughs I have seen on using MC files are not terribly helpful: mc_tutorial
MS mc.exe page
Could someone else walk me through what steps are nessary, or point me toward some more helpful resources?
An actual high quality man page for mc.exe would be quite nice, instead of the rather limited MS documenation, but maybe I am spoiled these days.
look for mc.exe in you machine (mc.exe is part of windows sdk usually located at C:\Program Files (x86)\Windows Kits\10\bin\10.0..\x64\mc.exe).
in windows command prompt run : "C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\mc.exe" -U sample.mc
after above command run: "C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\rc.exe" -r sample.rc
above command will generate header in your sample.mc file location.
run this command to generate dlls: link -dll -noentry -out:sample.dll sample.res

Resources