Catégories

C++20 project with Visual Studio

Temps de lecture : 3 minutes

We are in May 2021 and my version of Visual Studio is 16.9.5

Launch Visual Studio Installer

Then make sure Windows SDK is installed

W,ndows 10 0) : 
Débogueur juste-à-temps

Make sure C++ Modules for v142 build tools are also installed

Développement Desktop en C+ — 
Générez des applications C++ modernes pour Windows 
raide des outlls de votre choix, notamment MSVC, Clang... 
Développement mobile en .NET 
Générez des applications multiplateformes pour OS, 
Android ou Windows avec Xamarin. 
n 
IntelliCode 
AddressSanitizer + 
C++ MFC pour derniére version de Build T... 
Prise en charge de pour Build Too 
Modules C++ pour Build Tools v142 (x64/x... 
Outlls C++ Clang pour Windows (11.0.C 
Diagnostics JavaScript 
Incredi8uiId - Accélération de build 
Kit SDK W,ndows 10 (10.0.183620) 
SDK Windows 10 (10.0.17763.0)

Launch Visual Studio and create an empty project

Add a main.cpp file to the project and paste the following lines into the the source code

import std.core;

int main() {
	std::cout << "Grettings Professor Falken" << '\n';
}

Note that there are no include file. For information, here are the main modules to include:

  • std.core module provides most of the content of the C++ Standard Library
  • std.regex: the content of header <regex>
  • std.filesystem: the content of header <filesystem>
  • std.memory: the content of header <memory>
  • std.threading: the contents of headers <atomic>,  <condition_variable>,<future>, <mutex>, <shared_mutex>, <thread>

Highlight the project name in Solution Explorer and hit ALT+ENTER to access its properties. Make sure /MD and /EHsc are selected. To do so, select the C/C++ category then the Code generation option. Make sure properties are set for all platforms. If the Runtime library says something like "multiple option" select Debug or Release in the Configuration list box. In Debug mode you should select /MDd and /MD otherwise.

In the Language subcategory make sure that "Preview..." is selected in the "C++ Norm" option and that the "Experimental Modules" are activated (see below). In the next picture, note that the Configuration and Platform options are set to "all configurations" and "all platforms".

At this point we should be good to go. One last thing... Just to make sure our directory doesn't become a mess... Again, make sure Configuration and Platform options are set respectively to "all configurations" and "all platforms". Then in the General group of properties, update the Output directory and Intermediate directory as below:

Output Directory        : $(SolutionDir)build\$(Platform)$(Configuration)\
Intermediate directory  : $(SolutionDir)build\intermediate\$(Platform)$(Configuration)\

Click Apply then OK. When you're back in the IDE, select Debug and x64.

Hit F5. Welcome in a brand-new world!

Hopefully, the solution directory should not be too messy. Below the build directory contains all the files and directories generated during the builds.

At this point I would recommend saving this project as a template. This will speed up the start of your next C++20 project. To do so, select the Project menu then the "Export Template..." option. Then, follow the instructions and fill the dialog boxes. You can even add your own icon.

Later, a ready to use project will be available. See below the Cpp20 template for example.

1 comment to C++20 project with Visual Studio

  • Bonjour,
    With version 16.10 of Visual Studio (release yesterday I believe) I'm now able to write the code as below:

    import std.core;

    int main() {
    auto name = "Falken";
    std::cout << std::format("Grettings Professor {}\n", name); }

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.