Version numbers for Visual Studio 2017, Boost and CMake
Solution 1
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.
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
.
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.
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)
Finally we can consider the CMake function in FindBoost.cmake
. The _boost_COMPILER
should default to -vc141
if the compiler version is 19.10
.
Solution 2
CMake versions which are less than the official release v3.8.0, which includes the rc numbers have the following in their 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.
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..
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.
Related videos on Youtube
wally
Updated on June 06, 2020Comments
-
wally almost 4 years
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
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
During compilation the following variables are
#define
'd:_MSC_VER 1910 _MSC_FULL_VER 191025017
cl.exe
is contained within an MSVC folder with the VC tools version. The completex64
folder path isC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64
cl /Bv
from the command line lists: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
andlink.exe
are listed with version 14.10.25017.0.
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.When I compile I get the libraries names with v141 e.g.:
boost_atomic-vc141-mt-1_64.lib
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")
So which version should be used?
vc141
orvc150
? Does-
v141
implyvc141
, or does -
v141
implyvc150
?
-
Torbjörn about 7 years
vc150
seems like a bug in CMake's_Boost_GUESS_COMPILER_PREFIX
to me. What version of CMake are you using? VS2017's toolsetv141
is binary compatible with VS2015'sv140
and there is nov(c)150
I've heard of. Probably, the developer of that CMake macro was extrapolating and guessing the toolset for VS2017. -
wally about 7 years@Torbjörn Agreed. There is a VC 15.0, but no Toolset 15.0 (yet) and the filename refers to the toolset. I'm using CMake 3.8.0-rc1.
-
StAlphonzo almost 7 yearsIf you are using CMake version < 3.8.0 (including an RC version) you need to use 141. If you are using CMake version > 3.8.0 you need to use 150. This issue has to do with the way Boost changed their numbering scheme.
-
wally almost 7 years@StAlphonzo Thanks for the update. Could you point to the Boost numbering scheme change? I don't understand why it would be 150.
-
StAlphonzo almost 7 yearsI will add an answer so it formats correctly and fits in the tiny space.
-