Skip to content

Cpp2 setup: Visual Studio

Herb Sutter edited this page Oct 16, 2023 · 16 revisions

At the end of my CppCon 2023 talk, I showed debugging Cpp2 in Visual Studio. Several people asked how I set it up. Here's what I did.

Overview:

  • Add the .cpp2 file to the project.
  • Tell VS to build that file using a custom build step to invoke cppfront. (I assume you already have cppfront installed.)
  • That's it, once it builds the IDE and debugger should just pick up the error messages and debug step through the .cpp2 file.

Step by step

1. Add the .cpp2 file to the project

In the Solution Explorer, I just right-clicked on Source Files and picked Add to add the file to the project.

image

2. Tell VS to build that file using a custom build step to invoke cppfront

For some reason I first had to go into the Project > App Properties menu:

image

There, I added a Custom Build Tool:

image

Then in Solution Explorer I could right-click on the .cpp2 file and select Properties:

image

And select the custom build tool there too:

image

Note that I had to also tell it that the custom build tool produced the .cpp file.

Also, be sure to put the /cppfront/include directory on your INCLUDE path, in Solution Explorer right-click the app and select Properties:

image

And add it to the VC++ Directories > Include Directories:

image

That's it

That's all I did, and all that was just to invoke cppfront to build.

The IDE just picks up the rest from:

  • the cppfront error messages in filename(line, col) format which VS recognizes and merges any diagnostic output in the normal Errors window (if your IDE prefers filename:line:col just use the cppfront -format-colon-errors command line option)
  • the #line directives cppfront emits in the generated .cpp file so the debugger knows to step through the .cpp2 file (#line emission is on by default, but if you choose -clean-cpp1 these will be suppressed and then the debugger will step through the generated C++ code instead)