C++ Visual Studio 2017、Boost 和 CMake 的版本号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42730478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Version numbers for Visual Studio 2017, Boost and CMake
提问by wally
From the Boost mailinglist I understand that VS2017 has the following version numbers that we would probably be most interested in:
从 Boost 邮件列表中,我了解到 VS2017 具有以下我们可能最感兴趣的版本号:
Visual Studio 15.0
cl; C/C++ Compiler 19.10
Platform Toolset: v141
The following macros are defined in the Visual Studio 2017 IDE:
Visual Studio 2017 IDE 中定义了以下宏:
CrtSDKReferenceVersion 14.0
MSBuildToolsVersion 15.0
PlatformToolsetVersion 141
VCToolsVersion 14.10.25017
VisualStudioVersion 15.0
During compilation the following variables are #define
'd:
在编译期间,以下变量是 #define
'd:
_MSC_VER 1910
_MSC_FULL_VER 191025017
cl.exe
is contained within an MSVC folderwith the VC tools version. The complete x64
folder path is
cl.exe
包含在带有 VC 工具版本的 MSVC 文件夹中。完整的x64
文件夹路径是
C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.10.25017\bin\HostX64\x64
cl /Bv
from the command line lists:
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
1033\clui.dll: Version 19.10.25017.0
Notice mspdb140.dll
and link.exe
are listed with version 14.10.25017.0.
注意mspdb140.dll
和link.exe
与版本 14.10.25017.0 一起列出。
And hereit seems that msvc : 14.1
should be used as the toolset for boost. And here is another answerwhere some comments talk about boost's compiler naming.
而这里似乎msvc : 14.1
应该被用作工具集提升。而这里是另一个答案,其中一些意见谈升压转换器的编译器命名。
When I compile I get the libraries names with v141 e.g.: boost_atomic-vc141-mt-1_64.lib
当我编译时,我使用 v141 获取库名称,例如: boost_atomic-vc141-mt-1_64.lib
But in CMake the _Boost_GUESS_COMPILER_PREFIX
function has the following:
但是在 CMake 中,该_Boost_GUESS_COMPILER_PREFIX
函数具有以下功能:
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")
So which version should be used? vc141
or vc150
? Does
那么应该使用哪个版本呢?vc141
或者vc150
?做
v141
implyvc141
, or doesv141
implyvc150
?
v141
暗示vc141
或确实v141
暗示vc150
?
回答by wally
In order to answer this it would be best to start with
为了回答这个问题,最好从
- how Microsoft structures its products
- what Microsoft calls its products and
- how Microsoft numbers them.
- 微软如何构建其产品
- 微软称其产品和
- 微软如何编号。
So, on my system:
所以,在我的系统上:
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
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.
很明显,工具集版本应该是主要参考。特别是如果人们认为 VS 2017 可以使用v140
和v141
. 该工具集巧妙地定义了编译器和链接器。
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
.
那么,b2 toolset=msvc-14.0
例如,编译 Boost 意味着什么?我的论点是它意味着 toolset v140
,而不是 Microsoft Visual C++ 14.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.
如何使用工具集进行编译v141
?非正式地 msvc 通常是 VS 编号(例如15.0
,对于我系统上的 VS2017),但在指定工具集时会不准确。接下来,我们注意到 Boost 将创建一个文件,其名称包含vcXXX
wherevc
似乎再次暗示 Visual C++ 版本号的非正式概念,例如15.0
但肯定不能引用它,因为它是指定的工具集。
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.
因此,在 VS2017 上编译最新工具集的命令将是b2 toolset=msvc-14.1
生成文件名包含vc141
. 如果是这样,就不会那么混乱了v141
,但是这样就不会提醒我们正在处理 Microsoft 工具集。
I now think of the command as follows:
我现在想到的命令如下:
b2 toolset=msvc-14.1
---- ----
| |
| +-- Toolset v141
|
+------- Microsoft Visual C++ (version 15.0)
Finally we can consider the CMake function in FindBoost.cmake
. The _boost_COMPILER
should default to -vc141
if the compiler version is 19.10
.
最后我们可以考虑FindBoost.cmake
. 本_boost_COMPILER
应默认-vc141
如果编译器版本19.10
。
回答by StAlphonzo
CMake versions which are less than the official release v3.8.0, which includes the rc numbers have the following in their FindBoost.cmake.
低于官方版本 v3.8.0 的 CMake 版本,其中包括 rc 编号,在它们的 FindBoost.cmake 中有以下内容。
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
set(_boost_COMPILER "-vc150")
which means that, if your Boost dlls are not named like e.g. boost_date_time-vc150-mt-1_55.dll they won't be found. Version v3.8.0 started matching the approach Boost was taking with regard to version numbers, though I don't recall the in depth discussion of the matter. The short answer is though, if you are using a cmake version v3.8.0 or greater, you need the following instead.
这意味着,如果您的 Boost dll 没有像boost_date_time-vc150 -mt-1_55.dll那样命名,它们将不会被找到。版本 v3.8.0 开始匹配 Boost 在版本号方面采取的方法,尽管我不记得对此事的深入讨论。简短的回答是,如果您使用的是 cmake 版本 v3.8.0 或更高版本,则需要以下内容。
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.10)
set(BOOST_TOOLSET msvc-14.1)
For simplicity, in my Boost builds for Windows, I always add the following CMake code..
为简单起见,在我为 Windows 构建的 Boost 版本中,我总是添加以下 CMake 代码..
if(MSVC AND (NOT MSVC_VERSION LESS 1910))
# Get the CMAKE version string and make sure it's not a release candidate and >= 3.8.0
if( (CMAKE_VERSION MATCHES "^3\.8\.0-rc") OR (CMAKE_VERSION VERSION_LESS 3.8.0))
message(FATAL_ERROR "CMake 3.8.0 is the minimum version required to use Boost with Visual Studio 2017 or greater")
endif()
endif()
That lets me forget about the whole issue of what the libraries should be named.
这让我忘记了图书馆应该命名的整个问题。