Visual Studio 2017、Boost 和 CMake 的版本号

2022-01-12 00:00:00 cmake visual-studio-2017 c++ boost

来自 Boost 邮件 列表我知道 VS2017 有以下是我们可能最感兴趣的版本号:

From the Boost mailing list I understand that VS2017 has the following version numbers that we would probably be most interested in:

Visual Studio           15.0
cl; C/C++ Compiler      19.10
Platform Toolset:       v141

<小时>

以下宏在 Visual Studio 2017 IDE 中定义:


The following macros are defined in the Visual Studio 2017 IDE:

CrtSDKReferenceVersion  14.0
MSBuildToolsVersion     15.0
PlatformToolsetVersion  141
VCToolsVersion          14.10.25017
VisualStudioVersion     15.0

在编译期间,以下变量被#define'd:

During compilation the following variables are #define'd:

_MSC_VER                1910
_MSC_FULL_VER           191025017

cl.exe 包含在带有 VC 工具版本的 MSVC 文件夹中.完整的x64文件夹路径是

cl.exe is contained within an MSVC folder with the VC tools version. The complete x64 folder path is

C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.10.25017inHostX64x64

cl/Bv 来自命令行列表:

Compiler Passes:
 cl.exe:        Version 19.10.25017.0
 c1.dll:        Version 19.10.25017.0
 c1xx.dll:      Version 19.10.25017.0
 c2.dll:        Version 19.10.25017.0
 link.exe:      Version 14.10.25017.0
 mspdb140.dll:  Version 14.10.25017.0
 1033clui.dll: Version 19.10.25017.0

注意 mspdb140.dlllink.exe 列出的版本为 14.10.25017.0.

Notice mspdb140.dll and link.exe are listed with version 14.10.25017.0.

而 here 似乎 msvc : 14.1 应该用作 boost 的工具集.这里是另一个答案,其中一些评论谈到了 boost 的编译器命名.

And here it seems that msvc : 14.1 should be used as the toolset for boost. And here is another answer where some comments talk about boost's compiler naming.

当我编译时,我会得到带有 v141 的库名称,例如:boost_atomic-vc141-mt-1_64.lib

When I compile I get the libraries names with v141 e.g.: boost_atomic-vc141-mt-1_64.lib

但在 CMake 中,_Boost_GUESS_COMPILER_PREFIX 函数具有以下内容:

But in CMake the _Boost_GUESS_COMPILER_PREFIX function has the following:

if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
  set(_boost_COMPILER "-vc150")
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
  set(_boost_COMPILER "-vc140")

那么应该使用哪个版本呢?vc141 还是 vc150?有没有

So which version should be used? vc141 or vc150? Does

  • v141 隐含 vc141,或者是
  • v141 隐含 vc150?
  • v141 imply vc141, or does
  • v141 imply vc150?

推荐答案

为了回答这个问题最好先从

In order to answer this it would be best to start with

  • Microsoft 如何构建其产品
  • 微软对其产品的称呼和
  • Microsoft 如何对它们进行编号.

所以,在我的系统上:

Microsoft Visual Studio Community 2017 has version number 15.0.26228.4. It contains:
|
+--Visual C++, informally VS, informally MSVC 
   (no version number to be found, but it is reasonable to infer 15.0) 
   which uses tools, such as
   |
   +--Toolset v141, composed of
      |
      +--compiler cl.exe version 19.10.25017.0 and
      +--linker link.exe version 14.10.25017.0 which
         |
         +--refers to CrtSDK version 14.0, and
         +--uses mspdb140.dll version 14.10.25017.0

很明显,工具集版本应该是主要参考.特别是如果有人认为 VS 2017 可以同时使用 v140v141 构建.该工具集巧妙地定义了编译器和链接器.

It seems clear that the toolset version should be the main reference. Especially if one considers that VS 2017 can build both with v140 and v141. The toolset neatly defines both the compiler and linker.

那么,例如,用 b2 toolset=msvc-14.0 编译 Boost 意味着什么?我的论点是它意味着工具集 v140,而不是 Microsoft Visual C++ 14.0.

So then, what does it mean to compile Boost with b2 toolset=msvc-14.0 for example? My contention is that it means toolset v140, not Microsoft Visual C++ 14.0.

如何使用工具集 v141 进行编译?非正式地,msvc 通常是 VS 编号(例如,我系统上的 VS2017 的 15.0),但在指定工具集时会不准确.接下来,我们注意到 Boost 将创建一个名称包含 vcXXX 的文件,其中 vc 似乎再次暗示 Visual C++ 版本号的非正式概念,例如 15.0 但肯定不能引用它,因为它是指定的工具集.

How would one compile with toolset v141? Informally msvc is usually the VS number (e.g. 15.0 for VS2017 on my system), but that would be inaccurate when specifying a toolset. Next, we note that Boost will create a file with a name containing vcXXX where vc would again seem to imply the informal notion of a Visual C++ version number such as 15.0 but certainly cannot refer to that as it is the toolset that is being specified.

因此,为 VS2017 上的最新工具集编译该命令将是 b2 toolset=msvc-14.1,它将生成文件名包含 vc141 的库.如果它是 v141 就不会那么混乱了,但是这样就不会提醒我们正在处理 Microsoft 工具集.

So, compiling for the latest toolset on VS2017 the command would be b2 toolset=msvc-14.1 which will generate libraries with filenames containing vc141. It would have been less confusing had it been v141, but then there would have been no reminder that we're dealing with the Microsoft toolset.

我现在想到的命令如下:

I now think of the command as follows:

b2 toolset=msvc-14.1
           ---- ----
             |    |
             |    +-- Toolset v141
             |
             +------- Microsoft Visual C++ (version 15.0)

<小时>

最后我们可以考虑FindBoost.cmake中的CMake函数.如果编译器版本为 19.10,则 _boost_COMPILER 应默认为 -vc141.


Finally we can consider the CMake function in FindBoost.cmake. The _boost_COMPILER should default to -vc141 if the compiler version is 19.10.

相关文章