cl.exe mismatch between compiler and library versions when building Universal app - c++

I'm trying to build a Windows Universal app using cl.exe from the command line. I've pasted in the command line parameters from one of the Visual Studio templates, but I still can't get it working. I get the following error:
F:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vccorlib.h(348): error C3940: 'EventRegistrationToken': identifier not found - possible mismatch between compiler and library versions. Please ensure vccorlib.h/.lib, vccorlib120.dll and c1xx.dll match
It appears that it is using the wrong include libraries.
The cl.exe command line also includes the following options for include files:
/LIBPATH:"F:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\lib\store\amd64"
/LIBPATH:"F:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\\lib\amd64"

Fixed this by running vcvarsall.bat with the appropriate option, beforehand.

Related

Choose a certain version of Visual Studio's command line toolkit and compile files against a certain version of a C++ run-time environment

I'm using Visual Studio 2017. Trying to compile a package using certain version of the C++ toolkit and to compile against a certain version a c++ run-time environment.
In my case that would mean the latest toolkit against the latest c++ run-time environment libraries.
How do I make this happen? I tried to use /std:c++17 or /std:latest but this results in a build compiled against vc140.dll.
The documentation of neither cl.exe nor link.exe gives any kind of a hint.
Any ideas? Thanks.
In the project properties UI you can set platform Toolset on the "General" page.
For v140 the resulting command lines start:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe
but for v141 they start:-
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\bin\HostX86\x86\CL.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\bin\HostX86\x86\link.exe
You can read the command line for yourself if you set the build output to diagnostic (via Tools->Options->Build and Run).
You can set them here using the dropdown
(project properties)
(configuration properties)
(general)
(platform toolset)

Need help setting up CLANG on windows Properly

I need some help to set up clang on windows properly.
I have visual studios 2015 installed. And the Windows SDK.
I recently installed Clang, and ran a very basic hello world through it to make sure it's working correctly. And it gave me an error I can't make any sense out of.
Visual Studios will handle this just fine.
Here is the error output I've received from clang:
Microsoft Windows [Version 10.0.14393]
C:\Users\Leo>cd C:\Users\Leo\Desktop\Sandbox
C:\Users\Leo\Desktop\Sandbox>clang++ hello.cpp
In file include d from hello.cpp:1:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\iostream:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\istream:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\ostream:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\ios:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocnum:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\climits:5:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\yvals.h:8:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\crtdefs.h:10:10: fatal error:
'corecrt.h' file not found
#include <corecrt.h>
^
1 error generated.
C:\Users\Leo\Desktop\Sandbox>
Line 1 in hello.cpp is just:
#include <iostream>
So this error isn't making sense to me.
Type echo %INCLUDE% at the command prompt. To see your INCLUDE path.
Check to make sure your INCLUDE environment variable isn't set to a path that contains a Visual Studio path. Probably will need to do the same for the LIBenvironment variable as well.
I recently got it to work correctly, and compile windows applications. Including Directx11 and Directx12.
Turns out you would need to build Clang under Visual Studios after generating a Cmake project. If you wish to default to 64bit, you need to specify the 64bit version of Visual Studios.
Once it's compiled, you need to run clang-cl under the VSbuild tools.

MSVC can't find its libs

For some purpose that is not really important I used MSVC 2012 in console mode (Windows 8x64) and when I tried to compile "Hello, World!" it didn't find its stabdard library and linker couldn't find some of its lib-files. So in the end I managed to configure both compile and link commands to make them work properly:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe" -c main.cpp /I
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include"
and for link:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe"
main.obj
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib"
/LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86"
To sum up I want to know, how can they be configured so that cl found its headers and link found those libs. Please consider that I'm going to use them in Qt Creator, where they don't work and I've just found a way of getting them to work but from outside of Creator and I need to do it by Creators' means (nmake or jom options that is).
You need to call
call %ProgramFiles(x86)%\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
in your command line window. This sets up a usable environment.

C++ command line compiler for Visual Studio 2012

I have installed Visual Studio Express 2012 and I have added cl.exe to my PATH but apparently is missing a dll ( ? ), the mspdb110.dll, I have also noticed that there are 2 cl.exe in 2 different paths:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64
how i can compile a file main.cpp from the command line with the VS compiler ?
Where I can find a reference for this compiler ?
Thanks.
Run the vcvarsall.bat batch file from the VC directory under whatever directory you installed Visual Studio to (e.g., on my PC, it's in C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC). This batch file will configure the environment for toolchain use.
By default, it will configure the environment for use of the x86 native toolchain. You can also provide an argument to the batch file to use a different toolchain. For example, you can pass amd64 to use the native x64 toolchain, or x86_amd64 to use the x86 -> x64 cross compilation toolchain. Take a look at the contents of the batch file if you are interested in other options or what, exactly, it configures.

Error "fatal error C1034: windows.h: no include path set"

OS Windows Vista Ultimate
I am trying to run a program called minimal.c. When I type at the command line:
C:\Users\nathan\Desktop>cl minimal.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
minimal.c
minimal.c(5) : fatal error C1034: windows.h: no include path set
I have set all the paths:
C:\Users\nathan\Desktop>path
PATH=C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin;C:\Windows\system3
;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\ATI Technologies\AT
.ACE\Core-Static;C:\Program Files\Intel\DMIX;c:\Program Files (x86)\Microsoft S
L Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Bi
n\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Java\jdk1.
.0_13\bin;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files (x86)\Co
mon Files\Autodesk Shared\;C:\Program Files (x86)\Microsoft DirectX SDK (March
009)\Include;C:\Users\nathan\Desktop\glut-3.7.6-bin\glut-3.7.6-bin;C:\Program F
les (x86)\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files (x86)\Microsof
Visual Studio 8\VC\PlatformSDK\Include;C:\Program Files (x86)\Microsoft Visual
Studio 8\VC\PlatformSDK\Include\gl
I have gone and made sure windows.h is in the directory. I'm setting the path too. It's
in C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\Include.
I have Visual Studio 2005.
I have exhausted all possibilities. Any ideas?
You could also run the vcvars32.bat file from the directory C:\Program Files\Microsoft Visual Studio 8\VC\bin (this is in your path) prior to your cl command.
Like this:
C:\Users\nathan\Desktop>vcvars32
C:\Users\nathan\Desktop>cl minimal.c
vcvars32 calls C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat which sets up the required environment for compiling and linking.
The environment variables are INCLUDE, LIB, and PATH.
The compiler looks for header files in the INCLUDE path during compile, and libraries are fetched from the LIB path during link.
For me, with Visual Studio 2017,
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd.bat"
is the command to use before compiling with cl.
Here is the documentation.
When you started the command line, did you run the included command line shortcut that comes with the Visual Studio setup? This will set the correct environment variables for you so that the compilation will work correctly.
In your project folder, open a PowerShell window and run:
cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && cl minimal.c '
You've added your INCLUDE paths to your PATH environment variable. Use vcvars32.bat as the others have suggested.
Your path variable might be too long. Windows can’t take more than 1023 characters in the PATH environment variable.
I had the same issue getting the
fatal error C1034: stdio.h: no include path set
and after running the C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build>vcvars64.bat cmd/batch script would get the
fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
error message. From here, and other posts on that page, I suspected that the Windows 10 SDK package must be installed. After installation and running the vcvars64.bat script from the path mentioned above, the problem was solved.
P.S. As explained here, an alternative to manually finding and running the above cmd/batch script, you may just do +Q and search for Developer Command Prompt for ..., in my case it is Developer Command Prompt for VS 2022.
if you have version 2017 of the compiler cl.exe (you installed Visual Studio 2017), in the command prompt you need go to "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build" and run 'vcvars32.bat' for x86 compilation or vcvars64.bat for x64 compilation.