How can I run cl using x64? - c++

I had the same problem as here fatal error C1034: windows.h: no include path set
I typed vcvars32.bat and that solved my problem but I want to link some 64-bit .lib files and when I do:
cl main.cpp xxxlib.lib
I get:
warning LNK4272: library machine type 'x64' conflict with target machine type 'x86'
Is it because I use the vcvars32.bat is 32 bits? Where can I find the 64 bit version?
Thanks

In order to make sure you have the proper environment variables set, the simplest way is to launch the respective command shell in the start menu.
For 64bit, this would be Visual Studio x64 Win64 Command Prompt (2010), then cl.exe is automatically correct. If you show the properties of this entry in the start menu, you'll also find more infos:
Start in: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\"
Target : %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64
From this, you see that the working directory is set, and vcvarsall.bat is called with the amd64 parameter. This is probably what you missed.

Related

How to compile big c++ project using MsBuild.exe with x64 compiler

I have the big Visual Studio 2015 C++ project and can't compile it on the computer with 12GB RAM (fatal error C1060: compiler is out of heap space).
Command line:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Project.sln /t:Rebuild /p:Configuration=Release;Platform=x64
I've read this https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx?f=255&MSPPError=-2147217396
and decided to use x64 compiler, but I can't figure out how it can be done using MsBuild.exe (or with another way but without generate make file - it is hard to maintain it because the project frequently changed).
I was tried to call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" before MsBuild.exe, but it doesn't help.
Found solution here: https://msdn.microsoft.com/en-us/library/ee662426.aspx?f=255&MSPPError=-2147217396
Where is the property PreferredToolArchitecture which by default equals x86.
Set it to x64 to use the 64-bit compiler and tools to build your application.
msbuild myProject.vcxproj /p:PreferredToolArchitecture=x64

cl.exe not found in Visual Studio 2017 [duplicate]

I'm trying to compile a cuda test program on Windows 7 via Command Prompt,
I'm this command:
nvcc test.cu
But all I get is this error:
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
What may be causing this error?
You will need to add the folder containing the "cl.exe" file to your path environment variable. For example:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin
Edit: Ok, go to My Computer -> Properties -> Advanced System Settings -> Environment Variables. Here look for "PATH" in the list, and add the path above (or whatever is the location of your cl.exe).
For new Visual Studio cl.exe is present in path => C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\Hostx64\x64
x64 is for 64bit
x86 is for 32bit
Solve this problem by adding this options to nvcc
nvcc x.cu ... -ccbin "D:\Program Files\Microsoft Visual Studio 11.0\VC\bin"
for example my compiler is VS2012. and cl.exe is in this dir
cl.exe is Microsoft's C/C++ compiler. So the problem is that you don't have that installed where the command line can find it.
nvcc is only a front end for the CUDA specific part of the program. It must invoke a full compiler to finish the job. In this case it cannot find the Visual Studio compiler 'cl.exe'
Check paths, nvcc documentation etc.
I see that this is an old question but I recently got this error on my Visual Studio 2012 when I tried to build my CUDA project. Apparently I had changed my CUDA project to the Nov 2012 pack, changing it back to the v110 that it usually is by default fixed this error.
In Visual Studio, left click on the CUDA project, ->properties->Configuration Properties-> General -> Platform toolset, and choose: Visual Studio 2012 (v110).
I could probably get it to work with the Nov 2012 pack, but the CUDA code does not use any of the additional functions of that pack, so it is not necessary. (That pack contains the variadic templates for C++11.)
Solve this problem by adding the path to environment variables, which can vary slightly depending in the version of visual studio installed in your system, and are you using 32bit or 64bit system
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64

Couldn't build DLL of CURL library (C++) for x64 bit machine

This question is about curl library building for 64 bit machine.
Searched a lot in Google, but facing some errors.
Below are the things done so far.
-> Download CURL sources from below link.
https://curl.haxx.se/download/curl-7.52.1.zip
-> Extract the zip to curl-7.52.1 directory.
Open "Visual Studio 2008 Command Prompt" from Start -> Program Files -> Microsoft Visual Studio 2008
-> Run below command to change to curl downloaded directory.
$(WorkDir)\curl-7.52.1\winbuild>
-> Run below command to build curl library.
nmake /f Makefile.vc mode=dll machine=x64
-> After the build command, got below error:
..\builds\libcurl-vc-x64-release-dll-ipv6-sspi-winssl-obj-lib/file.obj : fatal e
rror LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\amd64\link.exe"' : return code '0x458'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\
VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
Could not found suitable solution for above errors.
It would be highly appreciated if someone can help to resolve the error.
Thanks in advance.
In Visual Studio there are environment variables that you have to set to get either x86 or x64 compiler. There are multiple ways to set these environment variables:
You have to find the batch file vcvarsall.bat, and use it to import the correct environment variables
You have to find the shortcut that starts a command prompt with 64-bit command prompt tools. The following is a screenshot from my blog explaining this:
So, you have to find that shortcut or learn how to use vcvarsall.bat. There are tons of tutorials about it there.
One important thing to keep in mind is that prior to Visual Studio 2012, 64-bit was not available in Visual Studio Express, so unless you have Visual Studio 2008 Professional, this won't be possible.
Hope this helps.

Building OpenSSL for WinCE in VS2008

I am trying to build OpenSSL 1.0.2 version using Visual Studio 2008 command prompt for Windows CE device. I am using Windows 7, 32 bit machine.
I am following the instructions that are mentioned in INSTALL.WCE file.
Below are the steps that I am following:
I have set PATH,LIB and INCLUDE variables.
Run “perl Configure VC-CE”
Run “ms\do_ms”
Run” nmake -f ms\ce.mak”
Below is the error that I am facing
lib /nologo /out:out32_ARMV4I\ssleay32.lib #C:\Users\AppData\Local\Temp\nmBC93.tmp cl/Fotmp32_ARMV4I\constant_time_test.obj -Iinc32 -Itmp32_ARMV4I /O1i /W3 /GF /Gy /nologo -D UNICODE -D_UNICODE -DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD - DOPENSSL_SMALL_FOOTPRINT -D_WIN32_WCE=500 -DUNDER_CE=500 -DWCE_PLATFORM_VC-CE -DARM -D_ARM_ -DARMV4I
-QRarch4T -QRinterwork-return /MT -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_ JPAKE -DOPENSSL_NO_DYNAMIC_ENGINE /Zi /Fdtmp32_ARMV4I/app -c .\crypto\constant_time_test.c
constant_time_test.c link /nologo /opt:ref /subsystem:windowsce,5.00 /machine:ARM /debug /out:out32_ARMV4I\constant_time_test.exe
C:\Users\AppData\Local\Temp\nmBE87.tmp tmp32_ARMV4I\constant_time_test.obj
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'ARM'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.EXE"' : return code '0x458' Stop.
As per my understanding this is falling since I am on a x86 machine and trying to build the library for ARM platform. How do I overcome this issue since VS2008 does not have cross-compiler. Can I built this without using wcecomapt library?
PATH, LIB and INCLUDE are incorrectly set; you seem to be building with the x86 toolchain. C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.EXE is the linker for x86, not ARM. The correct linker when using VS2008's cross compiler would be c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\bin\x86_arm\link.EXE.
INSTALL.WCE contains instructions for eMbedded Visual C++ that are not entirely applicable to VS2008 - in particular, the batch files that setup the environment are conspicuously missing from VS2008. You will have to find and/or make them yourself, which is pretty much about setting PATH, INCLUDE and LIB to point to the cross-compiler, the CE SDK's headers and libraries, respectively.
Assuming you do have a cross-compiler installed, either from VS2008 or one of the device SDKs, this should work. If you do not have a cross-compiler installed and since you are trying to build for CE 5, you could also get eMbedded Visual C++ which is freely available; be sure to grab the SP4 if you do so. With it, you should be able to follow the instructions in INSTALL.WCE to the letter.

Qt Windows x64 build succeeds in IDE but not on the command line

I have a Qt project I'm trying to automate. On Windows I build for both 32-bit and 64-bit platforms. I am using Visual Studio 2013. I have the following Qt Kits installed: Desktop Qt 5.5.1 MSVC2013 32bit, and Desktop Qt 5.5.1 MSVC2013 64bit. All four versions (32-bit debug and release, and 64-bit debug and release) can be built and run without any trouble from the IDE. Unfortunately, building from the command line fails with this error:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
My command-line system, intended for eventual use in a batch file, and run in my project directory, is:
pushd Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
call vcvars32.bat
popd
md build64
cd build64
G:\Qt\5.5\msvc2013_64\bin\qmake.exe -spec win32-msvc2013 -o Makefile ..\Maps.pro
G:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Release
I use this command in a command window (after setting up the path using vcvars32 so that the Visual Studio tools like nmake, rc and link can be found) and get the error. Note that the command-line method works perfectly for my 32-bit build.
The qmake command line I use is copied from the one recorded in a comment in the Makefile created by the IDE, which claims it is the command used to create that makefile. I know that the "-spec win32-msvc2013" option looks strange, but it works when the IDE uses it.
The jom command line I use is the one used by the IDE, as logged by the Compile Output window.
The only thing I can think of is that Qt sets up some 'magic' environmental variables which I don't know about.
[Yes, I have googled very extensively and looked at other questions and answers here, and can't find anything that fits this case.]
This code
pushd Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
vcvars32.bat
popd
sets up environment for building for 32-bit architecture. Run vcvars32.bat from different directory (I think it should have amd64 in its name, don't have Windows computer at the moment so can't say the exact directory name, but you'll figure out).
Or do
pushd "<DRIVE>:\Program Files (x86)\Microsoft Visual Studio <Version>\Common7\Tools"
vsvars32 x64
popd
Update for VS2017:
For 64-bit architecture use this command:
"<DRIVE>:\Program Files (x86)\Microsoft Visual Studio\2017\<Version>\VC\Auxiliary\Build\vcvars64.bat"
and for 32 bits:
"<DRIVE>:\Program Files (x86)\Microsoft Visual Studio\2017\<Version>\VC\Auxiliary\Build\vcvars32.bat"