C++ #include <atlbase.h> is not found - c++

When I compile my C++ program in Visual Studio Express it says that it can't find atlbase.h. Am I missing some SDK or something?

Visual Studio 2017
When running the Visual Studio Installer, select the Individual components tab, and under SDKs, libraries, and frameworks make sure Visual C++ ATL Support is selected.

It is included with the Windows Driver Kit Version 7.1.0.

Microsoft ATL (Active Template Library), which includes the header atlbase.h is included with the Windows 2003 SDK, but it is not included with any newer Windows SDK release. It is also included with Professional editions of Visual Studio.

Solution for Visual Studio 2017 Express edition
I had the same error when building a COM C++ project in Visual Studio 2017 Express edition. As mentioned by several users here, ATL support is not included with the Express edition of Visual Studio. So to build a C++ COM/ATL project you need at least the Community edition.
If you really need to use the Express edition, you can download and install the Build Tools for Visual Studio 2017. Make sure to enable the 'Visual C++ ATL for x86 and x64' component during the setup.
After that add additional VC++ directories in the project properties:
Include directories: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\atlmfc\include
Library directories: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\atlmfc\lib\x86
The VC++ compiler should now be able to find the ATL source and library files.

For users of Visual Studio 2015, ensure Common Tools for C++ is installed (part of the VS installer).

Situation
With Visual Studio 2017 Community Edition, we installed "Visual C++ ATL support" and MFC and ATL support. The error still occurred in our x64 project.
Solution
We fixed some paths with the following two commands:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>mklink /d atlmfc "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc"
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\lib>mklink /d amd64 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\lib\x64
Details
We eventually found the header atlbase.h in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\include. This path simply was not added to the VC Include directory by vsvars32.bat, so the header was not found during build.
vsvars32.bat includes the following line:
#if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE%`.
This resolved to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include in our machine.
We created a directory junction, so the build tool finds atlbase.h in the expected directory (this is the first command from the Solution section above):
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>mklink /d atlmfc "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc"
Afterwards, the linker did not find atls.lib (see Cannot Open File atls.lib). This was due to the expected file structure was that lib should directly contain the x86 version of the libs and lib\amd64 should contain the x64 variants. Instead, lib\x86 contained the x86 versions and lib\x64 contained the 64 bit versions. Since we build a 64 bit project, creating another directory junk from amd64 to x64 solved the problem:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\lib>mklink /d amd64 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\lib\x64

That header appears to be a part of the Windows Platform SDK.
You should search your computer for the file. That will tell you if you're missing it.

I had same problem with sample project. I specified the sample project's properties and the sample project compiled successfully.
Visual Studio 8
For header
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include
For .lib file
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib

I have not yet seen anyone mention Visual Studio 2015 (MSBuild 14.0). In this case I've had to download Visual C++ BuildTools (found here: https://visualstudio.microsoft.com/vs/older-downloads/). After having installed this, running the installer again allowed me to modify the installation and include the ATL libs.
Hope this helps anyone that is still using MSBuild 14.0

Related

Folder "Microsoft Visual Studio 14.0" Is Missing

I'm trying to add pthread library to Visual Studio 2017 (I'm using Windows 10 OS). I'm using the following guide from another post tat I saw, but I can't find the "Microsoft Visual Studio 14.0" folder in "C:\Program Files x86". I have Visual Studio 2017 and It's working. I've checked and I've installed the Visual Studio C++. What else should I install? Is there any other way to include pthread library by just adding it to the project and including the path to the library in the linker or something similar?
Thank you
Since visual studio 2017 visual studio is installed in C:\Program Files (x86)\Microsoft Visual Studio\<version>\<edition> by default e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community. There are other changes to the internal layout of files within the visual studio directory too. Your guide seems to only provide libraries for Visual Studio 2010 and 2012, these won't work in 2017, you should try to find an updated guide (or just use std::thread instead of pthreads).
Installing these files inside the visual studio directory isn't the right approach anyway, install them to a directory of your choice and update your project settings to point to that directory. The lazy approach in the guide is likely to cause problems in the long run.

Where should my project include new.h from? (Visual Studio and/or SDK corruption or version incompatibility?)

I have a project that started as a Visual Studio 2005 project, and is now a Visual Studio 2019 project. It is built using the 142 Platform Toolset on Windows 10, but for deployment on Windows 8.1 and later. So it selects the Windows 8.1 SDK, and sets WINVER, _WIN32_WINNT and _WIN32_WINDOWS all to 0x0603.
It's an MFC project, so stdafx.h is virtually everywhere. That includes afxwin.h, which in turn includes afx.h and that includes new.h. It all builds fine on my desktop development machine with version 16.4.3 of Visual Studio 2019 Community.
I have just tried building the project on a laptop just after upgrading to "the latest" Visual Studio version (16.6.2). It fails to build because it cannot find new.h. As far as I can tell, new.h should be part of the SDK. But new.h is not in the Windows 8.1 SDK (or at least: not mine).
But what really confuses me is that when I track down new.h in my successful build, also configured to use the Windows 8.1 SDK, it finds new.h in the Windows 10 SDK.
I'm not clear if I have (a) a bad project (b) 1 or more bad Visual Studio installations (c) 1 or more bad SDK installations. Where should I expect to find new.h under such circumstances, and does that shine any light on which of a, b or c I'm experiencing?
Case (d): you are missing the Windows SDK 8.1 installation on the laptop. That needs to be done separately from the VS install. From the Visual Studio 2019 v16.0 Release Notes - Deprecations:
The Windows 8.1 SDK is no longer available in the Visual Studio installer. Please upgrade your C++ projects to the latest Windows 10 SDK. If you have a hard dependency on 8.1, you can download it from the Windows SDK archive.
[ EDIT ] Targeting the Windows SDK 8.1 does not remove all references to the Windows 10 SDK, which is still required and used. For example, the include path for a C++ MFC project using the v142 toolset and the v8.1 SDK is set by default to the following on my machine.
C:\Program Files (x86)\Microsoft Visual Studio\2019\VC\Tools\MSVC\14.25.28610\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\VC\Tools\MSVC\14.25.28610\atlmfc\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\VC\Auxiliary\VS\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
C:\Program Files (x86)\Microsoft Visual Studio\2019\VC\Auxiliary\VS\UnitTest\include
C:\Program Files (x86)\Windows Kits\8.1\Include\um
C:\Program Files (x86)\Windows Kits\8.1\Include\shared
C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\Include\um

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)

ATL headers missing when using the VC++ 2015 toolchain on Visual Studio 2017

I am using Visual Studio 2017 for a C++ project (created with VS 2015). I get the following error:
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afx.h(345): fatal error C1083: Cannot open include file: 'atltrace.h': No such file or directory
How can I install the ATL/MFC headers of the VS 2015 toolchain?
Details
"Platform Toolset" setting (at "Project properties/General/Platform Toolset")
set to "Visual Studio 2015 (v140),
changing the platform toolset to "Visual Studio 2017 (v141) compiles fine.
Files on disc
The include directory for VS 2015 (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\) contains afx*.h files but no atl*.h files.
These missing files seem to belong to VC_ATL.Headers.msi ("Visual C++ Library ATL Headers Package") (which I checked on another machine with those files). I could not get the respective msi to install. (I took the msi from the other machine.) Error: "To install this product, please run Setup.exe. [...]".
The respective directory for VS 2017 (C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\atlmfc\include\) does contain those files.
Installer
"Windows Desktop Development with C++/VC++ 2015.3 v140 toolset for desktop (x86,x64)" is checked.
It seems to me that the v140 toolset is missing the ATL/MFC headers.
"Windows Desktop Development with C++/MFC and ATL support(x86 and x64)" does not seem relevant, it seems to be about the VS 2017 version.
VC++ redistributable seems irrelevant since those do not contain the header files.
There is a blog post about the Visual C++ Build Tools 2015. The build tools are also released in a standalone version without the need to install Visual Studio 2015:
The Build Tools are the same C++ tools that you get with Visual Studio 2015 but they come in a scriptable standalone installer that only lays down the tools you need to build C++ projects.
Microsoft has included ATL/MFC.
They can be downloaded from http://landinghub.visualstudio.com/visual-cpp-build-tools. Make sure to select "ATL and MFC" which is deselected by default.

Distribute msvcr120.dll with a c++ app that was created with Visual Studio 2015

I have created a c++ app using visual studio 2015. My distribution package requires files msvcp140.dll and vcruntime140.dll in order for my app to run correctly on another pc. According to https://www.visualstudio.com/license-terms/distributable-code-microsoft-visual-studio-2015-rc-microsoft-visual-studio-2015-sdk-rc-includes-utilities-buildserver-files/:
Visual C++ Runtime Files Subject to the License Terms for the
software, you may copy and distribute with your program any of the
files within the followng folder and its subfolders except as noted
below. You may not modify these files. C:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\redist
Since both of the above files reside in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist I can distribute these two files with my executable.
However I also need file msvcr120.dll due to a precompiled third party library that I also use. This file resides in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools.
I know that there is an option by using specific inno setup file to check which vc++ redistributables are needed and to installed the correct ones. However for the time being I just need to include the relevant dll in my executable setup package.
So my question is whether I'm allowed to distribute msvcr120.dll with my package as well?
If you have VS 2013 and you can find the msvcr120.dll file under C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\arm\Microsoft.VC120.CRT, for the detail information, please check this: Determining Which DLLs to Redistribute
If you do not install the VS 2013, their DLLS are also available as stand-alone redistributable packages from the Microsoft Download Center.
Refer to Distributable Code for Microsoft Visual Studio 2013 and Microsoft Visual Studio 2013 SDK (Includes Utilities & BuildServer Files) and you should be able to distribute the msvcr120.dll file from C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\arm\Microsoft.VC120.CRT.