Skip to content

Commit 7bf0952

Browse files
author
mikeblome
committed
fixed merge conflict
2 parents ea86138 + 5cd2657 commit 7bf0952

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

docs/porting/binary-compat-2015-2017.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: "C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2017"
3-
ms.date: "09/24/2018"
2+
title: "C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2019"
3+
ms.date: "05/03/2019"
44
helpviewer_keywords: ["binary compatibility, Visual C++"]
55
ms.assetid: 591580f6-3181-4bbe-8ac3-f4fbaca949e6
66
---
7-
# C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2017
7+
# C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2019
88

9-
In previous versions of Visual Studio, binary compatibility between object files (OBJs), static libraries (LIBs), dynamic libraries (DLLs), and executables (EXEs) built by using different versions of the compiler toolset and runtime libraries was not guaranteed. This has changed in Visual Studio 2017. In Visual Studio 2015 and Visual Studio 2017, the C++ toolset major number is 14 (v140 for Visual Studio 2015 and v141 for Visual Studio 2017). This reflects the fact that both the runtime libraries and the applications compiled with either version of the compiler are--for the most part--binary compatible. This means, for example, that if you have a DLL in Visual Studio 2015, you don't have to recompile it in order to consume it from an application that is built with Visual Studio 2017.
9+
In Visual Studio 2013 and earlier, binary compatibility between object files (OBJs), static libraries (LIBs), dynamic libraries (DLLs), and executables (EXEs) built by using different versions of the compiler toolset and runtime libraries was not guaranteed.
1010

11-
There are two exceptions to this rule. Binary compatibility is not guaranteed in these cases:
11+
In Visual Studio 2015 and later, the C++ toolset major number is 14 (v140 for Visual Studio 2015, v141 for Visual Studio 2017, and v142 for Visual Studio 2019). This reflects the fact that both the runtime libraries and the applications compiled with either version of the compiler are binary compatible. This means that if you have third-party library that was built with Visual Studio 2015, you don't have to recompile it in order to consume it from an application that is built with Visual Studio 2017 or Visual Studio 2019.
1212

13-
1. When static libraries or object files are compiled with the `/GL` compiler switch.
13+
The only exception to this rule is that static libraries or object files that are compiled with the `/GL` compiler switch are not binary compatible.
1414

15-
2. When consuming libraries built with a toolset whose version is greater than the toolset used to compile and link the application. For example, a program that is compiled and linked with compiler version 19.12 can consume libraries that are compiled with 19.0 up through 19.12. Also, binary compatibility only exists between Visual Studio 2015 and Visual Studio 2017; linking 19.x programs with libraries produced by Visual Studio 2013 or earlier is not supported.
15+
When you mix binaries built with different supported versions of the MSVC toolset, the Visual C++ redistributable that your application runs on cannot be older than any of the toolset versions used to build your app or any libraries it consumes.
1616

1717
## See also
1818

docs/porting/overview-of-potential-upgrade-issues-visual-cpp.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Overview of potential upgrade issues (Visual C++)"
3-
ms.date: "11/04/2016"
3+
ms.date: "05/03/2019"
44
ms.assetid: 2c99a8cb-098f-4a9d-bf2c-b80fd06ace43
55
---
66
# Overview of potential upgrade issues (Visual C++)
@@ -14,15 +14,20 @@ Questions or comments about the upgrade process can be sent to vcupgrade@microso
1414

1515
## Library and toolset dependencies
1616

17+
> [!NOTE]
18+
> This section applies to applications and libraries built with Visual Studio 2013 and earlier. The toolsets used in Visual Studio 2015, Visual Studio 2017 and Visual Studio 2019 are binary compatible. For more information, see [C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2019](binary-compat-2015-2017.md).
19+
1720
When upgrading an application to a new version of Visual Studio, it is strongly advisable and in many cases necessary to also upgrade all libraries and DLLs that the application links to. This requires either that you have access to the source code, or that the library vendor can provide new binary files compiled with the same major version of the compiler. If one of these conditions is true, then you can skip this section, which deals with the details of binary compatibility. If neither of these are the case, then you might not be able to use the libraries in your upgraded application. The information in this section will help you understand whether you can proceed with the upgrade.
1821

1922
### Toolset
2023

2124
The .obj and .lib file formats are well-defined and rarely change. Sometimes additions are made to these file formats, but these additions generally do not affect the ability of newer toolsets to consume object files and libraries produced by older toolsets. The one big exception here is if you compile using [/GL (Whole Program Optimization)](../build/reference/gl-whole-program-optimization.md). If you compile using `/GL`, the resulting object file can only be linked using the same toolset that was used to produce it. So, if you produce an object file with `/GL` and using the Visual Studio 2017 (v141) compiler, you must link it using the Visual Studio 2017 (v141) linker. This is because the internal data structures within the object files are not stable across major versions of the toolset and newer toolsets do not understand the older data formats.
2225

23-
C++ does not have a stable application binary interface (ABI). Visual Studio maintains a stable C++ ABI for all minor versions of a release. For example, Visual Studio 2017 and all its updates are binary compatible. But the ABI is not necessarily compatible across major versions of Visual Studio (except for 2015 and 2017, which _are_ binary compatible). That is, we may make breaking changes to C++ type layout, name decoration, exception handling, and other parts of the C++ ABI. Thus, if you have an object file that has external symbols with C++ linkage, that object file may not link correctly with object files produced with a different major version of the toolset. Note that here, "may not work" has many possible outcomes: the link may fail entirely (e.g. if name decoration changed), the link may succeed and things may not work at runtime (e.g. if type layout changed), or things may happen to work in many cases and nothing will go wrong. Note also that while the C++ ABI is not stable, the C ABI and the subset of the C++ ABI required for COM are stable.
26+
C++ does not have a stable application binary interface (ABI). But Visual Studio maintains a stable C++ ABI for all minor versions of a release. Visual Studio 2015 (v140), Visual Studio 2017 (v141) and Visual Studio 2019 (v142) vary only in their minor version. They all have the same major version number, which is 14. For more information, see [C++ Binary Compatibility between Visual Studio 2015 and Visual Studio 2019](binary-compat-2015-2017.md).
27+
28+
If you have an object file that has external symbols with C++ linkage, that object file may not link correctly with object files produced with a different major version of the toolset. Note that here, "may not work" has many possible outcomes: the link may fail entirely (for example, if name decoration changed), the link may succeed and things may not work at runtime (for example, if type layout changed), or things may happen to work in many cases and nothing will go wrong. Note also that while the C++ ABI is not stable, the C ABI and the subset of the C++ ABI required for COM are stable.
2429

25-
If you link to an import library, any later version of the Visual Studio redistributable libraries that preserve ABI compatibility may be used at runtime. For example, if your app is compiled and linked using the Visual Studio 2015 Update 3 toolset, you can use any Visual Studio 2017 redistributable, because the 2015 and 2017 libraries have preserved backward binary compatibility. The reverse is not true; you can't use a redistributable for an earlier version of the toolset than you used to build your code, even if they have a compatible ABI.
30+
If you link to an import library, any later version of the Visual Studio redistributable libraries that preserve ABI compatibility may be used at runtime. For example, if your app is compiled and linked using the Visual Studio 2015 Update 3 toolset, you can use any Visual Studio 2017 or Visual Studio 2019 redistributable, because the 2015 and 2017 libraries have preserved backward binary compatibility. The reverse is not true; you can't use a redistributable for an earlier version of the toolset than you used to build your code, even if they have a compatible ABI.
2631

2732
### Libraries
2833

@@ -32,15 +37,15 @@ For the C++ Standard Library, mixing-and-matching has been explicitly disallowed
3237

3338
For the CRT, mixing-and-matching was never supported, but it often just worked, at least until Visual Studio 2015 and the Universal CRT, because the API surface did not change much over time. The Universal CRT broke backwards compatibility so that in the future we can maintain backwards compatibility. In other words, we have no plans to introduce new, versioned Universal CRT binaries in the future. Instead, the existing Universal CRT is now updated in-place.
3439

35-
To provide partial link compatibility with object files (and libraries) compiled with older versions of the Microsoft C Runtime headers, we provide a library, legacy_stdio_definitions.lib, with Visual Studio 2015 and later. This library provides compatibility symbols for most of the functions and data exports that were removed from the Universal CRT. The set of compatibility symbols provided by legacy_stdio_definitions.lib is sufficient to satisfy most dependencies, including all of the dependencies in libraries included in the Windows SDK. However, there are some symbols that were removed from the Universal CRT for which it is not possible to provide compatibility symbols like this. These symbols include some functions (e.g., \_\_iob\_func) and the data exports (e.g., \_\_imp\_\_\_iob, \_\_imp\_\_\_pctype, \_\_imp\_\_\_mb\_cur\_max).
40+
To provide partial link compatibility with object files (and libraries) compiled with older versions of the Microsoft C Runtime headers, we provide a library, legacy_stdio_definitions.lib, with Visual Studio 2015 and later. This library provides compatibility symbols for most of the functions and data exports that were removed from the Universal CRT. The set of compatibility symbols provided by legacy_stdio_definitions.lib is sufficient to satisfy most dependencies, including all of the dependencies in libraries included in the Windows SDK. However, there are some symbols that were removed from the Universal CRT for which it is not possible to provide compatibility symbols like this. These symbols include some functions (for example, \_\_iob\_func) and the data exports (for example, \_\_imp\_\_\_iob, \_\_imp\_\_\_pctype, \_\_imp\_\_\_mb\_cur\_max).
3641

3742
If you have a static library that was built with an older version of the C Runtime headers, we recommend the following actions (in this order):
3843

3944
1. Rebuild the static library using Visual Studio 2017 and the Universal CRT headers to support linking with the Universal CRT. This is the fully supported (and thus best) option.
4045

4146
1. If you cannot (or do not want to) rebuild the static library, you may try linking with legacy\_stdio\_definitions.lib. If it satisfies the link-time dependencies of your static library, you will want to thoroughly test the static library as it is used in the binary, to make sure that it is not adversely affected by any of the [behavioral changes that were made to the Universal CRT](visual-cpp-change-history-2003-2015.md#BK_CRT).
4247

43-
1. If your static library’s dependencies are not satisfied by legacy\_stdio\_definitions.lib or if the library does not work with the Universal CRT due to the aforementioned behavioral changes, we would recommend encapsulating your static library into a DLL that you link with the correct version of the Microsoft C Runtime. For example, if the static library was built using Visual Studio 2013, you would want to build this DLL using Visual Studio 2013 and the Visual Studio 2013 C++ libraries as well. By building the library into a DLL, you encapsulate the implementation detail that is its dependency on a particular version of the Microsoft C Runtime. (Note that you will want to be careful that the DLL interface does not leak details of which C Runtime it uses, e.g. by returning a FILE* across the DLL boundary or by returning a malloc-allocated pointer and expecting the caller to free it.)
48+
1. If your static library’s dependencies are not satisfied by legacy\_stdio\_definitions.lib or if the library does not work with the Universal CRT due to the aforementioned behavioral changes, we would recommend encapsulating your static library into a DLL that you link with the correct version of the Microsoft C Runtime. For example, if the static library was built using Visual Studio 2013, you would want to build this DLL using Visual Studio 2013 and the Visual Studio 2013 C++ libraries as well. By building the library into a DLL, you encapsulate the implementation detail that is its dependency on a particular version of the Microsoft C Runtime. (Note that you will want to be careful that the DLL interface does not leak details of which C Runtime it uses, for example, by returning a FILE* across the DLL boundary or by returning a malloc-allocated pointer and expecting the caller to free it.)
4449

4550
Use of multiple CRTs in a single process is not in and of itself problematic (indeed, most processes will end up loading multiple CRT DLLs; for example, Windows operating system components will depend on msvcrt.dll and the CLR will depend on its own private CRT). Problems arise when you jumble state from different CRTs. For example, you should not allocate memory using msvcr110.dll!malloc and attempt to deallocate that memory using msvcr120.dll!free, and you should not attempt to open a FILE using msvcr110!fopen and attempt to read from that FILE using msvcr120!fread. As long as you don’t jumble state from different CRTs, you can safely have multiple CRTs loaded in a single process.
4651

@@ -99,7 +104,7 @@ The same issue applies also if you use the `/ENTRY` option or the `/NOENTRY` opt
99104

100105
## Errors due to improved language conformance
101106

102-
The Microsoft C++ compiler has continuously improved its conformance to the C++ standard over the years. Code that compiled in earlier versions might fail to compile in Visual Studio 2017 because the compiler correctly flags an error that it previously ignored or explicitly allowed.
107+
The Microsoft C++ compiler has continuously improved its conformance to the C++ standard over the years. Code that compiled in earlier versions might fail to compile in later versions of Visual Studio because the compiler correctly flags an error that it previously ignored or explicitly allowed.
103108

104109
For example, the `/Zc:forScope` switch was introduced early in the history of MSVC. It permits non-conforming behavior for loop variables. That switch is now deprecated and might be removed in future versions. It is highly recommended to not use that switch when upgrading your code. For more information, see [/Zc:forScope- is deprecated](porting-guide-spy-increment.md#deprecated_forscope).
105110

@@ -121,11 +126,11 @@ The [/showIncludes](../build/reference/showincludes-list-include-files.md) compi
121126

122127
Many changes have been made to the C runtime over the years. Many secure versions of functions have been added, and some have been removed. Also, as described earlier in this article, Microsoft’s implementation of the CRT was refactored in Visual Studio 2015 into new binaries and associated .lib files.
123128

124-
If an error involves a CRT function, search [Visual C++ change history 2003 - 2015](visual-cpp-change-history-2003-2015.md) or [C++ conformance improvements in Visual Studio](../overview/cpp-conformance-improvements.md) to see if those topics contain any additional information. If the error is LNK2019, unresolved external, make sure the function has not been removed. Otherwise, if you are sure that the function still exists, and the calling code is correct, check to see whether your project uses `/NODEFAULTLIB`. If so you need to update the list of libraries so that the project uses the new universal (UCRT) libraries. See the section above on Library and dependencies for more information.
129+
If an error involves a CRT function, search [Visual C++ change history 2003 - 2015](visual-cpp-change-history-2003-2015.md) or [C++ conformance improvements in Visual Studio](../overview/cpp-conformance-improvements.md) to see if those topics contain any additional information. If the error is LNK2019, unresolved external, make sure the function has not been removed. Otherwise, if you are sure that the function still exists, and the calling code is correct, check to see whether your project uses `/NODEFAULTLIB`. If so you need to update the list of libraries so that the project uses the new universal (UCRT) libraries. For more information, see the section above on Library and dependencies.
125130

126131
If the error involves `printf` or `scanf`, make sure that you are not privately defining either function without including stdio.h. If so, either remove the private definitions or link to legacy\_stdio\_definitions.lib. You can set this in the **Property Pages** dialog under **Configuration Properties** > **Linker** > **Input**, in the **Additional Dependencies** property. If you are linking with Windows SDK 8.1 or earlier, then add legacy\_stdio\_definitions.lib.
127132

128-
If the error involves format string arguments, this is probably because the compiler is stricter about enforcing the standard. See the change history for more information. Please pay close attention to any errors here because they can potentially represent a security risk.
133+
If the error involves format string arguments, this is probably because the compiler is stricter about enforcing the standard. For more information, see the change history. Please pay close attention to any errors here because they can potentially represent a security risk.
129134

130135
## Errors due to changes in the C++ standard
131136

@@ -149,7 +154,7 @@ For more information about the current API set and the minimum supported operati
149154

150155
### Windows version
151156

152-
When upgrading a program that uses the Windows API either directly or indirectly, you will need to decide the minimum Windows version to support. In most cases Windows 7 is a good choice. For more information see [Header file problems](porting-guide-spy-increment.md#header_file_problems). The `WINVER` macro defines the oldest version of Windows that your program is designed to run on. If your MFC program sets WINVER to 0x0501 (Windows XP) you will get a warning because MFC no longer supports XP, even though the compiler itself has an XP mode.
157+
When upgrading a program that uses the Windows API either directly or indirectly, you will need to decide the minimum Windows version to support. In most cases Windows 7 is a good choice. For more information, see [Header file problems](porting-guide-spy-increment.md#header_file_problems). The `WINVER` macro defines the oldest version of Windows that your program is designed to run on. If your MFC program sets WINVER to 0x0501 (Windows XP) you will get a warning because MFC no longer supports XP, even though the compiler itself has an XP mode.
153158

154159
For more information, see [Updating the Target Windows Version](porting-guide-spy-increment.md#updating_winver) and [More outdated header files](porting-guide-spy-increment.md#outdated_header_files).
155160

0 commit comments

Comments
 (0)