Quantcast
Channel: C++ Team Blog
Viewing all 1541 articles
Browse latest View live

C++14 conformance improvements: constexpr and aggregate initialization

$
0
0

Two important features in C++11 received small upgrades in C++14 that had far-reaching effects.

  1. In C++11, constexpr function bodies were allowed only to be a single return statement. In C++14, nearly all statements are now allowed in constexpr functions, allowing for much more idiomatic C++. You can learn more about what’s allowed in core constant expressions on CppReference as well as learn about constexpr on the same site.
  2. An aggregate type in C++11 could not be initialized as an aggregate if it contained any members that had default member initializers. In C++14 the committee removed this restriction on non-static data members having default member initializers. You can find out more about aggregate initialization on CppReference as well as about non-static data member initialization (known as NSDMI.)

You can see from the CppReference site that while both of these changes were small changes to the standard (search for the “C++14” annotation on those pages) they had broad impact on the compiler’s implementation and on what code developers can write.

  • Previously, constexpr was basically all about expressions, but C++14 extended it to allow control flow statements. The difference in what you can write in your code is huge: now instead of just being able to write expressions you can create idiomatic compile-time value compilations and mutation.
  • The changes to allow aggregate initialization for aggregates that contain non-static data members makes a useful case of aggregate initialization possible.

We’re happy to announce that the compiler shipping with Visual Studio 2017 supports both extended constexpr and NSDMI for aggregates fully.

Extended constexpr

Our extended constexpr work was test-driven. We tested against a number of libraries that are heavy users of extended constexpr, including:

  • Sprout
  • Boost (with MSVC workarounds removed)
  • Boost Hana
  • Guidelines Support Library (GSL)
  • libc++ tests
  • Microsoft’s Range-v3 fork
  • C++ Standard Libraries

We’ve also evaluated against test suites from McCluskey, Plumhall, and Perennial, as well as a test suite built from code snippets you sent us from an online survey, online forums, and early bug reports from the VC Blog.

Taking advantage of C++14 constexpr is almost as easy as putting the constexpr keyword on existing functions, because extended constexpr allows a developer to use idiomatic C++ for their constexpr functions.

  • Local variable declarations and conditionals can now be used in constexpr functions. [see example 1 below]
  • Instead of recursion, all looping constructs (except goto) are allowed in constexpr functions [see example 2 below]

Using iteration instead of recursion should perform better at compile time, and, as constexpr functions can be used at runtime, will perform better at runtime as well. We’ve beefed up our constexpr control flow engine to eagerly identify cases where a constexpr function is guaranteed to evaluate illegal expressions, so a class of errors can be caught at constexpr-authoring time rather than after a library has been shipped to developers.

constexpr examples

// Example 1a
enum class Messages {
	Hi,
	Goodbye
};

// Example 1b
constexpr bool even(int x) {
	if (x % 2 == 0)
		return true;
	return false;
}

// Example 2a
constexpr int simple_count_up_do_loop(int x) {
	int i = 0;
	do	{
		++i;
	} while (i < x);
	return i;
}

// Example 2b
constexpr int multiple_initializers_multiple_incr_count_up(int x) {
	int higher = 0;
	for (auto i = 0, j = 1; i <= x; ++i, j++)
		higher = j;
	return higher;
}

// Negative test cases
constexpr bool always(int x) {
	return x;
}

constexpr int guaranteed_to_hit_true_path() {
	if (always(1))
		throw "OH NO"; // illegal expression, guaranteed to be hit
	return 0;
}

constexpr int guaranteed_to_hit_false_path() {
	if (42 * 2 - 84)
		return 1;
	else
		throw "OH NO"; // illegal expression, guaranteed to be hit
	return 0;
}

constexpr int guaranteed_to_evaluate_while_loop() {
	while (always(33)) {
		new int(0);    // illegal expression, guaranteed to be hit
	}
	return 0;
}

constexpr int guaranteed_to_evaluate_for_loop() {
	for (; always(22); )
		new int();     // illegal expression, guaranteed to be hit
	return 0;
}

NSDMI for aggregates

The NSDMI for aggregates changes were more limited in scope but automatically improve a lot of existing code. In C++ 11, the presence of a default member initializer (NSDMI) would preclude the class from being an aggregate; therefore, it would not be eligible for aggregate initialization.

An example:

struct S {
  int i = 1;
  int j = 2;
};

S s1;   // OK; calls the default constructor, which initializes 'i' and 'j' to 1 and 2.
S s2{}; // OK; not aggregate initialization because S is not an aggregate; calls the default constructor.
s3{42}; // Error; S is not an aggregate and there is no appropriate constructor.

In C++14, S is now considered to be an aggregate class type, so aggregate initialization can be used:

S s4{}; // OK with C++14; aggregate initialization; no initializer is provided for 'i' or 'j', so their respective default member initializers will be used to initialize them to 1 and 2.
S s5{42}; // OK with C++14; aggregate initialization; 'i' is explicitly initialized to 42 and no initializer is provided for 'j', so its default member initializer will be used to initialize it to 2.

In closing

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with Visual C++ in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice. Thank you!


C++ Standards Conformance from Microsoft

$
0
0

Since we first shipped Visual Studio 2015 we’ve talked a lot about Microsoft Visual C++ compiler and library (MSVC) conformance improvements in this blog. Our team has been focused on making MSVC the best compiler toolset for your development on Windows, and that starts with fully conforming to the existing C++ Standard. This post will look back on the progress we’ve made in MSVC and look forward to our plans in the next version.

We’re not just implementing the C++ Standard, we’re helping to develop it. The MSVC team is a major contributor to the development of the C++ Standard. In addition to our participation in the standards committee meeting, editors from three major Technical Specifications (Coroutines, Modules, and Ranges) work on the MSVC team. We also maintain an open source fork of the Ranges TS that works on our compiler.

Creating a conforming toolset

In 2015 we started on a project that would fundamentally change how our compiler parses and analyzes code. We call this work “compiler rejuvenation,” a term that’s used in Jim Springfield’s excellent blog post from September 2015. We first shipped the rejuvenation work with VS 2015, but we’re still working on it today. It’s always been important for us to show value in our current compiler, maintain compatibility with existing code, and still prepare for a future where MSVC fully conforms to the standard.

Our compiler conformance progress shows the benefits of both the rejuvenation work and other conformance work. We’ve implemented almost all of the features introduced in the C++11 and C++14 standards. There are always bugs, of course, but only three feature areas remain unimplemented. We don’t yet have two-phase name lookup from C++98, we don’t have a conforming preprocessor, and we still have an incomplete implementation of Expression SFINAE.

This progress reflects a huge investment across the compiler but we’ve made especially big gains in Expression SFINAE as well as work on constexpr and extended constexpr: our implementation now conforms to the C++14 rules about extended constexpr. We very much appreciate our customers’ eagerness to tell us where we still have issues. This was especially true with regards to constexpr, where over 150 of you sent us code samples that showed us constexpr bugs remaining in our compiler. All the code snippets your provided in the survey have been turned into test cases. They are all passing with the VS 2017 compiler.

We’ve also heard from you through Connect, User Voice, Report a Problem in the IDE, e-mail, Twitter @visualc, Facebook at Microsoft Visual Cpp, and many other channels. We’ve consistently fixed between 200 and 300 developer-reported bugs in each update. Thank you for taking the time to help us identify issues!

Fixing conformance bugs in our toolset inevitably requires some changes in your source code. It’s not always easy to migrate all your code to new compiler features all at once. We introduced the standards version switches last year that let you opt-in to using features from the latest draft standard (i.e., C++17). And we’ve created a new conformance mode in the compiler, /permissive-, that lets you opt into a mode that disables Microsoft-specific conformance issues. Lastly, we’ve started to update the _MSC_VER compiler version macro with every compiler build. This lets you test programmatically for exactly what version of the compiler is compiling your code.

Some legacy bugs and non-standard behaviors in our compiler would have unintended runtime implications and incorrect behavior. Fixing those bugs in the default mode of the compiler is necessary in order to move the compiler forward towards conformance. When these changes are introduced, we carefully track all of them and provide before/after code snippets with recommendations and rationales for making the changes.

Sometimes, as with the recent keyword changes made by the standards committee in the Coroutines TS, we can’t control required code changes. But we know that it’s important to minimize any changes you have to make in your code when moving to a newer toolset.

Staying current with new features

We’ve spent a lot of time on conformance issues, but we haven’t just been catching up. We’ve been implementing C++ 17 compiler features as time permits. We’ve shipped a few draft standard features in the compiler and have another dozen queued up to release with the next update of VS 2017.  Our goal is to complete implementation of the C++17 standard when the standard is approved by ISO. Our current plan is to finish features by the end of the calendar year 2017.

We’ve also continued to make good progress in implementing library features as the standard develops. You might remember that with VS 2015 Update 2 we were feature complete for C++17 features approved at that point. We expect to have all of the major C++17 library features implemented before the standard is published.

Our first focus is on the remaining standards conformance features missing from MSVC. There are two big features still missing in MSVC: two-phase name lookup from C++98 and the C++ preprocessor from C++11. We also have significant work remaining on Expression SFINAE. We’ve started implementation of two-phase name lookup under the new conformance mode, /permissive-, and will preview two-phase name lookup support in mid-2017. And we have plans to start implementing a preprocessor that conforms to the standard. We’re also looking forward to implementing the remaining C++17 features as well as some notable Technical Specifications such as Concepts.

We maintain a summary of compiler features and standard library features for the MSVC toolset. You can use this list to track our progress as we implement C++17 language and library features.

Beyond conformance, which we consider table stakes for a modern C++ compiler, we are also heavily and continually investing in codegen performance, security, build throughput, diagnostics and analysis so that we can be the best compiler toolset on Windows.

Conformance integration with the VS IDE

We have not only delivered conformance improvements in our compiler toolset, we’ve also made the same conformance changes in the VS C++ IDE. You might remember that we use a (separate compiler, EDG, for IDE productivity features.) We carefully turn on behavior in EDG to match conformance fixes as they are made in our toolset.

For example, here’s the Visual Studio 2017 showing constexpr evaluation when hovering over a variable in the editor:

intellisense-for-conformance-improvements

In closing

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with MSVC in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice. Thank you!

Completed UserVoice Suggestions in Visual Studio 2017

$
0
0

Visual Studio 2017 RTM has shipped.

We could not have done it without you. Your suggestions and feedback on UserVoice. More than 6,000 of you have participated on the Visual C++ feedback forum and have cast thousands of votes for hundreds of suggestions.

This release includes 37 completed suggestions totaling 1546 votes from 772 unique community members. Did you make or add your votes supporting any of these suggestions?

Remember, if you voted on completed items, your votes are returned so you can support other suggestions. And if you have not yet made a suggestion or voted, you can participate in Visual Studio by Help > Send Feedback > Provide a Suggestion.

We look forward to your feedback.

C++ game development workload in Visual Studio 2017

$
0
0

Visual Studio 2017 introduces a new “Game development with C++” workload, making it easy to get tools you need for building high-quality games with C++. Whether you’re using DirectX or powerful game engines such as Unreal Engine or Cocos2d, Visual Studio can install everything you need all at once to get you started quickly.

In this blog post, we will talk about how to install Visual Studio for four different C++ game development scenarios: DirectX games for desktop, DirectX games for Universal Windows Platform (UWP), games with the Unreal Engine, and games with the Cocos2d engine.

Install Visual Studio for DirectX desktop development

First, download Visual Studio 2017. In the Visual Studio installer, choose the “Game development with C++” workload under the “Mobile & Gaming” category. This workload gives you the core tools to build DirectX games for desktop and includes the Visual Studio core editor, Visual C++ compiler, Windows Universal C Runtime, and Visual Studio debugger.

Install Visual Studio for DirectX desktop

The Optional component list on the right side of the installer lets you choose additional components that are useful for building DirectX games. The checked components are highly recommended:

Install Visual Studio for DirectX UWP development

You can build DirectX games for the Universal Windows Platform to run a variety of devices in the Windows family, including desktops, tablets, and phones. If this interests you, download Visual Studio 2017 and in the Visual Studio installer select the “Universal Windows Platform development” workload under the “Windows” category with the “C++ Universal Windows Platform tools” option selected. The C++ UWP component adds the core C++ UWP support and 3 DirectX project templates for DirectX11 and DirectX12 to get you started quickly. The “Graphics debugger and GPU profiler” component is highly recommended for DirectX development, as it brings in the Graphics Diagnostics feature for DirectX graphics debugging and GPU Usage feature for profiling GPU and CPU usage in DirectX games.

Install Visual Studio for DirectX UWP

Install Visual Studio for building games with Unreal Engine 4

Unreal logo

Unreal Engine 4 is a complete suite of creation tools designed to meet ambitious artistic visions while being flexible enough to ensure success for teams of all sizes. From 2D mobile games to console blockbusters and VR, Unreal Engine 4 gives you everything you need to start, ship, grow and stand out from the crowd. Use the full power of Visual Studio to edit, build, and debug your Unreal games in C++ to boost your productivity.

First, download Visual Studio 2017.download Visual Studio 2017. In the Visual Studio installer, choose the “Game development with C++” workload under the “Mobile & Gaming” category. This workload gives you the core tools to build C++ games for desktop, including Visual Studio core editor, Visual C++ compiler, Windows Universal C Runtime, and Visual Studio debugger. For building games with the Unreal Engine, check the “Unreal Engine Launcher” option on the right. This will download and install the Epic Game Launcher from the Unreal Engine site.

Install Visual Studio for Unreal Engine games

Once the installation is complete, you will find a shortcut for “Epic Games Launcher” on your desktop. In the Epic Games Launcher, you can download and install different versions of the Unreal Engine. After the Unreal Engine is installed, you are all set to start building your Unreal games! Launch the Unreal Engine from within the Epic Games Launcher and start creating new C++ Unreal projects in the Unreal Editor.

Epic Games Launcher

Write code with the full Visual Studio IntelliSense and source code browsing capabilities and debug your Unreal games with the powerful Visual Studio debugger. More on Visual Studio for UE4.

Install Visual Studio for building games with Cocos2d

cocos-logo

Cocos is an open-source professional development toolkit for building games that provides a streamlined workflow for developers. With Cocos, you can quickly create projects, design games and animation clips, package and publish games for distribution. Use Visual Studio to edit and debug your Cocos games efficiently with confidence.

First, download Visual Studio 2017. In the Visual Studio installer, choose the “Game development with C++” workload under the “Mobile & Gaming” category. This workload gives you the core tools to build C++ games for desktop, including Visual Studio core editor, Visual C++ compiler, Windows Universal C Runtime, and Visual Studio debugger. For building games with the Cocos2d engine, check the “Cocos” option on the right. This will download and install the Cocos Creator editor from the Cocos2d-x site.

Install Visual Studio for Cocos

Once the installation is complete, you will find a shortcut for “Cocos Creator” on your desktop and you can start creating new Cocos projects in the Cocos Creator. Write code with the full Visual Studio IntelliSense and browsing capabilities and debug your Cocos games with the powerful Visual Studio debugger.

Tell us what you think

Download Visual Studio 2017 [link to be added], try out the C++ game workload, and let us know what you think. For problems, let us know via the Report a Problem option in the upper right corner of the VS title bar. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice. We look forward to hearing from you!

 

Use any C++ Compiler with Visual Studio

$
0
0

Microsoft Visual Studio 2017 supports several C++ compilers to suit a wide variety of codebases.  In addition to the Microsoft Visual C++ compiler that many of you are likely familiar with, Visual Studio 2017 also supports Clang, GCC, and other compilers when targeting certain platforms.

This post is intended to familiarize you with the variety of C++ compilers that are compatible with the Visual Studio IDE, and to understand when they might be applicable to use with your projects.  Some compilers may be better suited to your needs depending on your project or target.  Alternatively, you may be interested in checking out new language features, such as C++ Concepts, that are not available across all compilers without needing to leave the IDE.

You can select the compiler and corresponding toolset that will be used to build a project with the “Platform Toolset” property under General Configuration Properties for C++ projects.  Any installed compilers that are applicable to your project type will be listed in the “Platform Toolset” dropdown.

Microsoft C++ Compiler (MSVC)

If you are targeting Windows, the Microsoft C++ compiler (MSVC) may be the way to go.  This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.

Compiler options for the Microsoft C++ compiler.

Compiler options for the Microsoft C++ compiler.

Clang

You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.

If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project.  Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS.  Support for Android and iOS is included in the “Mobile Development with C++” workload.  For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.

If you are targeting Windows, you have a few options:

  1. Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
  2. Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation).

Compiler options for the Clang/C2 compiler.

Compiler options for the Clang/C2 compiler.

It might make sense to use Clang/C2 if you want to bring a codebase that takes advantage of Clang’s language features to the Windows platform.  Since the code generation and optimization is handled by the MSVC backend, binaries produced by Clang/C2 are fully compatible with binaries produced by MSVC.  You can learn more about Clang/C2 from Clang with Microsoft Codegen – or check out the latest updates in posts tagged with the keyword “clang”.

GCC

If your project targets Linux or Android, you can consider using GCC.  Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang.  You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.

Compiler options for GCC.

Compiler options for GCC.

Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC.  If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.

Closing

Visual Studio also makes use of the Edison Design Group (EDG) frontend to provide flexible IntelliSense regardless of whether you use MSVC, Clang, or GCC to build your code.  Visual Studio gives you access to a wide range of choices when it comes to C++ compilers.  This way you can make sure that as you develop your code, it continues to compile against all major compilers.

Install Visual Studio today and give it a try.  Please let us know if we have missed any compilers you use, and share your feedback as we look forward to improving your C++ development experience.

MSVC: The best choice for Windows

$
0
0

The C++ product team here at Microsoft offers a great C++ experience in the Visual Studio IDE, the Visual Studio Code editor, and various other tools and services. That includes the topic of this blog post: the Microsoft Visual C++ compiler and libraries toolset (MSVC).

Our goal for MSVC is to be the best compiler choice on Windows for targeting Windows, regardless of what editor or IDE you choose to use. We aim to deliver on our goal with continuous investments in the following key areas: full C++ conformance, better errors and warnings, runtime performance, reliability, build throughput, and the best security. Let’s look at each one in more detail.

The best C++ conformance

Getting to full conformance with the C++ Standard is our number one priority when it comes to our compiler. We’ve written a dedicated post discussing our road to conformance. Please go read C++ Standards Conformance from Microsoft.

Better errors and warnings

Effective compiler diagnostics are hard. We know that there are many places where our warnings and errors could improve. We’ve started small, by indicating the column number in MSVC diagnostics. But there is more targeted work to come in the area of improved diagnostics: conforming behavior for ternary operator, missing diagnostics for incorrect code, detailed continuation messages for generic error codes, better warning level configurations for system headers, and more. Look for details on this blog in the coming months.

Similarly, we’ve been making great strides in the quality and variety of warnings generated from our C++ code analysis. One good example of this is the C++ Core Guidelines checkers, which ship as part of VS 2017. These checkers are built to enforce rules in the C++ Core Guidelines, a cross-industry coding standard that helps you write code that is correct by design.

We’ve made a number of improvements recently in C++ code analysis. We’ve made improvements in the base rulesets for code analysis in VS 2017 and in the C++ Core Guidelines checkers.

Code generation and optimization (runtime performance of your code)

We have three goals in optimizing your code, and we aim to be the best in each area:

  1. Runtime performance of your code: we want it to run as fast as possible.
  2. Reliability and correctness: It doesn’t matter how fast your code is if does the wrong thing. Our first focus is reliability of the compiler and correct code generation.
  3. Security: Lots of tools search for memory vulnerabilities from “outside the box”. Our optimizer contains powerful technology to make your code safe without tools.

With regards to runtime performance, our optimization framework got a big rewrite with VS 2015 Update 3. MSVC’s new SSA (static single assignment) optimization framework opens up new possibilities for how we can make your code run faster. We’re taking advantage of this new optimization framework in VS 2017 to make your code faster.

Optimization isn’t just about speed: it’s about correctness. We test our compiler, libraries, and optimizer daily by building Windows and Office as well as more than 50 OSS projects. We also have almost a million custom-written regression tests that run with every source change checkin, full-suite testing with several hundred thousand more tests daily, and performance and throughput testing.

There are many tools that try to make your code secure from outside the box: Valgrind and address/thread sanitizers are popular examples. And there are many of these tools on Windows as well, both from Microsoft and other companies. But MSVC features powerful technologies inside the compiler that integrate security with your code. For example, Control Flow Guard, is highly-optimized security feature that combats many memory corruption vulnerabilities. We can’t talk openly our current security research but we’re always working to make your code (and ours!) safe from increasingly sophisticated attackers.

Build throughput

We’ve also greatly improved build throughput: making our compiler toolset compile your code faster. Features like /debug:fastlink in VS 2015 reduced link times by 2-4x. In VS 2017, feature improvements to /debug:fastlink give an additional 30% reduction in link time. Here are more suggestions on how to use /debug:fastlink as well as other techniques for faster build times.

How do I get the newest MSVC toolset?

The best way to get our compiler and libraries toolset is as part of the latest version of Visual Studio. Major changes to the VS installer let you install just the parts you need. You can install just the C++ workloads without having to install other languages if that’s what you prefer. You can also optionally install workloads for specific C++ scenarios.

You can even install the C++ Build Tools on your build machines without needing to install the VS IDE. These are the same tools that are installed with VS 2017 but are intended for build machines. There’s usually no need to install an IDE on a build machine because no development happens on the machines. With VS 2017 you can choose to install just the MSVC toolsetin a scriptable, standalone installer.

What if you want to check out new features that have been implemented since the last VS update? We’ve created a simple way to try out a new toolset with an easy-to-install NuGet package that installs in a C++ project or solution. We’ve also helped to get our compiler toolset integrated on the Compiler Explorer at gcc.godbolt.org, a popular web app that lets you compare compiler features and code generation across many C++ compiler toolsets.

For libraries, we’ve created a Windows-specific library package manager that lets you quickly and easily install many open source libraries directly from their repos. We started with an initial list of libraries that you suggested in a survey, plus some of the most popular libraries from GitHub. The number of supported libraries that you can install with VCPkg is always growing.

In closing

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with MSVC in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice. Thank you!

Binary Compatibility and Pain-free Upgrade: Why Moving to Visual Studio 2017 is almost “too easy”

$
0
0

Visual Studio 2017 is a major leap forward in terms of C++ functionality compared with VS 2015. We hope the new release will delight you in your day-to-day job as soon as you can upgrade.

This blog post focuses on the steps needed to upgrade from Visual Studio 2015 to 2017. As promised in our BUILD 2016 talk “6 reasons to move your C++ code to Visual Studio 2015” (click to jump to 1h:04), in this release, our team made it distinctively easy to move your codebase to Visual Studio 2017. And here are the four reasons why.

Get MSVC 2015.3 toolset via the Visual Studio 2017 Installer

Loading your C++ projects targeting an older C++ toolset inside Visual Studio 2017 does not change your project. This allows you to load it back in the previous IDE in case you need to go back, or you still have teammates that are not fully upgraded to 2017. To make it zero-impact to load your existing projects inside Visual Studio 2017, just like in previous releases, the IDE supports project round-tripping.

In previous releases, you had to install both the latest and the old Visual Studio side-by-side for the latest IDE to be able to build your projects. Visual Studio 2017 allows you now to install the MSVC 2015 (v140) toolset directly, making it convenient to bootstrap a new machine as well as reducing the disk footprint of the installation by only installing the needed toolset and not the whole VS 2015 IDE bits.

installerplatform-toolset-selection

VC Runtime in MSVC 2017 is binary compatible with 2015

There are a lot of improvements in the C++ compilers and libraries in this release of Visual Studio that will entice you to move to Visual Studio 2017’s latest toolset (v141) – new standard conformance features, improved codegen, faster build throughput. You may be worried however that your third-party library dependencies are not ready for such a jump. We often hear from customers that this is the number one migration blocker to a new C++ toolset (whether they consume dependencies as binaries or even directly as source).

With the latest MSVC toolset however, you don’t need to worry about this at all. That’s simply because the latest VC Runtime is binary compatible with the VS 2015’s VC Runtime. In other words, if you have a library built with the v140 platform toolset, that binary and your code consuming it will continue to work even if you built your code with the v141 MSVC toolset.

Any binaries built with MSVC v141 toolset will link against the 140 version of the VC Runtime. The VCRedist is only backward compatible, so you will need to redistribute the latest VCRedist 140 available in VS 2017 with your app.

C:\src\ClockApp\Debug>dumpbin ClockApp.exe /IMPORTS | findstr .dll
mfc140ud.dll
KERNEL32.dll
USER32.dll
GDI32.dll
COMCTL32.dll
OLEAUT32.dll
gdiplus.dll
VCRUNTIME140D.dll
ucrtbased.dll

Hundreds of C++ libraries on Vcpkg are now available for Visual Studio 2017

If you haven’t heard about VCPkg yet, no worries – it’s an open-source project from Microsoft to help simplify the acquisition and building of open-source libraries on Windows. If you did use Vcpkg with Visual Studio 2015 for one or more of your open-source dependencies, then you will be happy to learn that these libraries (close to 180 at the time of this writing) are now compiled using MSVC v141 toolset and available for consumption in Visual Studio 2017 projects.

Because v141 is binary compatible with v140, all your existing packages will continue to work without recompilation; however, we do recommend recompiling when you can to enjoy the new compiler optimizations we’ve added to v141!

MSVC compiler version revs to 19.1 (from 19.0 in Visual Studio 2015)

Last but not least, the compiler part of the MSVC v141 toolset is revving only as a minor version in Visual Studio 2017. Note that we continue to make important progress towards C++ conformance as well as improved codegen. As these improvements are made, certain changes to make your code standards-conformant may be required on your side. All these changes are documented in our C++ conformance improvements in Visual Studio 2017 topic on docs.microsoft.com.

compiler-version

Call to action

Visual Studio 2017 comes with many new capabilities that we want you to take advantage of as soon as possible. That’s why we’ve made it probably “too easy” to migrate your projects from Visual Studio 2015. Try it today and let us know what you think!

Before you go, also check out the rest of our announcement posts for VS 2017 launch event, download Visual Studio 2017 and share your feedback with us either in the comments below or on developercommunity.visualstudio.com

Check for const correctness with the C++ Core Guidelines Checker

$
0
0

This blog post was written by Sunny Chatterjee and Andrew Pardoe

The C++ Core Guidelines focus on simple ways that you can improve the correctness and safety of your code. We introduced the C++ Core Guidelines Checkers to help automate enforcement of the C++ Core Guidelines in your code.

One of the easiest and most important changes you can make to your code is to mark immutable data as `const`. It’s not us and the Core Guidelines who believe that: see this fantastic blog post from Bruce Dawson about the benefits of adding const to your code. (He also mentions that on MSVC removing const can make some code faster, but that reflects a compiler bug that we are fixing thanks to Bruce’s feedback.) Because const is so important we’ve added a new C++ Core Guidelines checker about const correctness.

We created four new rules in the C++ Core Guidelines checker that cover all of the rules in the currently contained in the Constants and Immutability section of the C++ Core Guidelines. We didn’t actually add these checks for all of the rules—we implemented a check for rule #2, “By default, make member functions const” but removed it because it raised too many false positives on valid code—see below for details. Also, the tool will not warn that you could mark a stub function as const because we recognize that you’ll probably just remove the const later when you implement the function.

Const checker rules

Con.1: By default, make objects immutable

This rule is a general idea that states that we should always mark objects as const unless we’re writing to them. We cover this rule through more specific implementation of subsequent rules in our checker.

Con.3: By default, pass pointers and references to consts

Our checker enforces this rule. You can pass a pointer or reference to a non-const object, but if you do so, the caller shall assume their argument will be modified. If the function does not modify the object, we should mark the object as const to make the intent explicit.

Advantages of this check
  • Makes the intention of the callee explicit to the caller about whether or not an argument will be modified.
  • Future modifications in function body doesn’t change the expectations of the caller.

We use certain heuristics to reduce noise –

  • We don’t ask to mark arguments that are passed by value or the pointer arguments themselves as const.
  • We don’t ask unused arguments be marked as const since we don’t have enough information about their intent.
  • We don’t enforce this on virtual functions as the author may want to follow a specific derived behavior.
Examples
// Expect 26461: The input pointer argument b in function f7 can be marked as const
int f7(const int *a, int *b)
{
    return *a + *b;
}

struct S0
{
    virtual void m();
};

// Expect 26461 on 'p' but don't report on unnamed parameter.
S0 f8(int *p, int *)
{
    (p == nullptr);

    // Don't report on return UDT.
    return{};
}

Con.4: Use const to define objects with values that do not change after construction

Our checker enforces this rule. It’s similar to con.3, but applies to all variables and not just pointer or reference arguments. It helps prevent surprise from unexpected changes in object values.

Advantages of this check are pretty similar to con.3
  • Makes it easier to reason about code if we know if an object is immutable at the point of declaration.
  • Future modification of the code cannot change the immutable property of the object.

Like con.3, we use certain heuristics to reduce noise –

  • We avoid suggesting const usage on un-used variables – they rarely add any value.
  • We don’t suggest to mark the pointer or reference themselves as const, since users mostly care about the data that they point to.
Examples
int f5()
{
    // Expect 26496: Variable m is assigned only once, use const.
    int m = 5;
    const int a = 10;
    if (m > a)
        return m;
    return a;
}

Con.5: Use constexpr for values that can be computed at compile time and F.4: If a function may have to be evaluated at compile time, declare it constexpr

Our checker encourages programmers to declare functions that may have to be evaluated at compile time as constexpr.

Examples
// Expect 26497: could be marked constexpr if compile-time evaluation is desired
int f1(int a, int b)
{
    return a + b;
}

constexpr int f2(int a, int b)
{
    return a + b;
}

void f3()
{
   // Compile-time evaluation
    constexpr int m = f2(10, 20);

    // Expect 26498: This function call f2 can use constexpr if compile-time evaluation is desired.
    const int m2 = f2(10, 20);
}

Rule 2: the one we didn’t include

Con.2: By default, make member functions const

In the initial prototype, we included this check. However, after running this check on some real-world code, we decided to remove it from the shipping version of the checker. We didn’t want programmers to mark their member functions as const when they were logically non-const. For the intrepid, there’s a good discussion of logical and physical constness on the isocpp.org web page: https://isocpp.org/wiki/faq/const-correctness#logical-vs-physical-state.

Here’s an example where the member function is logically non-const. You could mark member function bar as const, e.g., void bar() const { *data_  = GetData(); }. While it doesn’t alter the pointer data_ itself, it could alter the memory pointed to by data_. Thus this function is not logically const.

class Test
{
public:
    // This method should be marked “const” since it doesn’t change the logical state of the object.
    MyData foo() const { return *data_; }

    // This method shouldn’t be blindly marked as “const”. It doesn’t alter the pointer data_ itself.
    // However, it alters the state of memory pointed-to by it.
    void bar() const { *data_ = GetData(); }

private:
    // data_ is a pointer to a “MyData” object
    MyData *data_;
};

 

Send us your feedback!

As always, we welcome your feedback. For problems, let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself.For suggestions, let us know through UserVoice. And you can always reach us through e-mail at cppcorecheck@microsoft.com.


C++ Code Analysis improvements in Visual Studio 2017 RTM

$
0
0

This blog post was written by Sunny Chatterjee and Andrew Pardoe

Visual Studio 2017 RTM  release includes the C++ Core Guidelines Checkers as part of Code Analysis tools for C/C++. We have gotten a ton of useful feedback on the early previews of these checks through our external customers. Thank you for engaging with us and giving us great feedback. This feedback helped us improve the quality of the final released version of  C++ Core Guidelines checks. Some of these improvements are explained in detail in this blog post about const correctness.

Besides shipping the C++ Core Guidelines checker, we also fixed  more than 150 bugs in our core analysis engine. All of these fixes are available in the Visual Studio 2017 RTM. As a result, developers should expect to see accuracy improvements in C++ code analysis. Download Visual Studio 2017 today and let us know what you think of the improvements to code analysis!

Here are some notable fixes that were frequently reported. These fixes were made as a result of direct external feedback.

  1. False positive during dereferencing null-pointer checks (C6011)
    1. https://connect.microsoft.com/VisualStudio/feedback/details/1645136/c6011-occurs-const-cast-to-const-members-after-if-statement
    2. https://connect.microsoft.com/VisualStudio/feedback/details/1981990/inappropriate-analyzer-warning-when-casting-to-reference-in-constructor
    3. http://connect.microsoft.com/VisualStudio/feedback/details/2556936/static-analysis-c6011-warning-false-positive-in-short-circuited-conditionals
    4. https://connect.microsoft.com/VisualStudio/feedback/details/2750342/static-analysis-false-positive-when-using-a-bracketed-ternary-operator
    5. https://connect.microsoft.com/VisualStudio/feedback/details/3078125/false-positive-dereferencing-null-pointer-warning-when-taking-a-named-reference
    6. https://connect.microsoft.com/VisualStudio/feedback/details/3082362/static-analysis-false-positive-when-comparing-ptr-nullptr-vs-simply-ptr
  2. False positive during uninitialized memory checks (C6001)
    1. http://connect.microsoft.com/VisualStudio/feedback/details/1858404/false-positive-in-c-static-analysis-c6001
    2. https://connect.microsoft.com/VisualStudio/feedback/details/2607792/erroneous-report-from-sal
  3. False positive around inconsistent annotation checking (C28252 and C28253)
    1. http://connect.microsoft.com/VisualStudio/feedback/details/2053524/wsutil-compiler-version-1-0095-creates-a-file-that-triggers-warnings-c28252-and-c28253-even-when-compiled-with-w0
  4. False positive during annotation parsing (C28285)
    1. http://connect.microsoft.com/VisualStudio/feedback/details/2358718/sal-analysis-warning-c28285-when-using-local-static-variables
  5. False positive during strict type match checking (C28039)
    1. https://connect.microsoft.com/VisualStudio/feedback/details/2573764/sal-false-positive-on-strict-type-match
  6. False positive when checking for local vs. global declarations on enum classes (C6244)
    1. https://connect.microsoft.com/VisualStudio/feedback/details/3101212/incorrect-static-analysis-warning-of-enum-class-enumerators-hiding-other-declarations
  7. MSBuild error MSB4018 during code analysis runs: The “MergeNativeCodeAnalysis” task failed unexpectedly
    1. https://connect.microsoft.com/VisualStudio/feedback/details/3113987/error-msb4018-the-mergenativecodeanalysis-task-failed-unexpectedly

Send us your feedback!

We hope that the C++ Code Analysis tools in Visual Studio 2017 help improve your code and make you more productive. We’d like to thank you all and as always, we welcome your feedback. Please tell us what you like and dislike about our current toolset and what you’d like to see in future releases.

For problems, let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. And you can always reach us through e-mail at cppcorecheck@microsoft.com.

Visual Studio 2017 for C++ developers – you will love it

$
0
0

Here on the C++ product team at Microsoft, our mission is to make the lives of every C++ developer on the planet better. We try to do that via various avenues, including but not limited to,

  1. by enthusiastically participating with the C++ Standards committee to help the language itself be better for every C++ developer in the world,
  2. by providing the Microsoft Visual C++ (MSVC) Compiler, which we aim to be the best compiler choice on Windows for targeting Windows,
  3. by continuing to enhance the C++ extension for Visual Studio Code, which is useful to all C++ developers regardless of the platform they do their development on, and finally,
  4. by improving Visual Studio, which is the most fully-featured IDE on the planet.

It is that last investment, Visual Studio, which I wanted to focus on in this blog post. Specifically, we’ll focus on the latest release, Visual Studio 2017, which we are confident you are going to love! We have blogged previously about the value in VS2017, so this post will just be a summary pointing to older posts we wrote that are now all updated for the final RTM release. First, we’ll summarize the new installation experience, then how it is pain-free to upgrade, then the new capability to open any folder of code (including CMake-based solutions), then how Visual Studio is for everyone, and finally what is new for productivity and performance.

Faster installation and your hard disk will thank you

When you install VS2017, you’ll encounter a new screen that organizes your installation options by what we call “Workloads”, so you can pick the one(s) that you care about while ignoring the others. The workloads most relevant to C++ developers are: Universal Windows Platform development, Desktop Development with C++, Game development with C++, Mobile development with C++, and Linux development with C++.

This is exciting because it makes it easy for you to pick exactly what you want to have installed, without the bits that you don’t, e.g. no ASP.NET bits if you are not also a web developer. The obvious benefits are that you end up with less visual noise while you are using the product, less use of your disk space, and you can get everything installed faster! For example, if you only pick the Linux development with C++ workload, you can get it all installed in under 6 minutes on a typical developer machine. The Desktop Development with C++, which most Visual Studio C++ users use today, takes less than 12 minutes. It is worth mentioning that what you are seeing is not only a reorganization at the UI level, but a complete rewrite of our installer.

vc2017_installing

Pain-free upgrade

Before joining Microsoft, when I was a customer, I was always excited about a new Visual Studio version, but also apprehensive about “upgrading” my projects and dealing with a few new errors/warnings on my codebase that worked fine in the “older” Visual Studio.

If you are currently using VS2013 or older, and you initially want everything to continue working as it was, there is good news for you: just use the older compiler and libraries toolset that is already on your disk with the latest Visual Studio. If you are already using VS2015, even on a clean machine (instead of side-by-side), you’ll notice in the new VS2017 acquisition experience described in the previous section that there is an option to install just the toolset that shipped with VS2015 (rather than the whole VS2015 IDE), so that you can continue using the older toolset while enjoying the benefits of the latest VS2017 IDE!

Of course one of the many reasons you are moving to VS2017 is to use the latest toolset with build throughput improvements, faster generated code, and the standards conformance goodness of the latest compiler and libraries so you will upgrade to the latest toolset, which by the way is binary compatible with the one that ships with VS2015. You can further take advantage of the standard version compiler switches and the permissive-  switch that help you ease into the conformance at your own pace. For any language conformance changes you encounter, you’ll find we put significant effort in making our documentation great for that eventuality.

Finally, for any open source 3rd party libraries you depend on, our new package management solution vcpkg with its growing repository of libraries has your back. And if you have adopted that already for your VS2015 projects, you’ll find they automatically work when you move to VS2017.

vc2017_props

Just point Visual Studio to your code

In the previous section, we touched on upgrading projects where the assumption was that you already have Visual Studio projects, or more accurately MSBuild-based projects. What about those of you who use other C++ build systems, such as makefiles or CMake? Until this VS release, you needed to create VS projects and add your code to that, or somehow generate a VS project from your current build system. Now, you can just “Open Folder” with any code directly in Visual Studio 2017! Depending on your build system you will automatically get some IntelliSense, navigation, building, and debugging capabilities… and you can improve those experiences by further configuring and adding information in JSON text files. For those of you who have chosen CMake, you will love the CMake-support in Visual Studio, just point VS to your CMakeLists.txt files and enjoy.

vc2017_cmake

Use Visual Studio for all your projects and target platforms

When we talk to some of you, we know you keep an older version of Visual Studio side-by-side with the latest. As we already established earlier in this post, there should be no reason for you to use the old IDE, just use the older toolset in that project with the latest Visual Studio 2017 IDE.

Some of you use VS for one project, but not for your other projects. In the past, there were many valid reasons for that, such as you didn’t want to convert your nmake-based (or other non-MSBuild-based) codebase to MSBuild; as established earlier, now you can just point Visual Studio 2017 to any folder of C++ code and work with it.

Another reason we hear is that folks use Visual Studio to target Windows, and other IDEs to target other platforms. Again, there is no need for that now. As touched on earlier when talking about workloads, from Visual Studio you can target Android and iOS and Linux. Implicit in that statement is that you should also not be thinking about Visual Studio as the IDE that only pairs with the Microsoft compiler, instead you can use any C++ compiler you want with Visual Studio.

Some of you may prefer using editors instead of IDEs, and that is fine, check out the Visual Studio Code editor. And when you need some heavy debugging, you can easily switch to Visual Studio for that purpose (by launching the EXE as a project or attaching to the running process) and then switch back to your editor of choice.

In short, if you have chosen Windows as your development environment, regardless of what platform you target or what kind of project you are working on, Visual Studio 2017 is there to support you as a C++ developer.

vc2017_workloads

Be more productive than ever

The blog post until now has been essentially about how fast and easy it is to install the product, and how many options you have for getting your codebase in Visual Studio and make sure it builds. You are now ready to do real development, and for many of you, productivity is the main reason you use Visual Studio. It saves you a lot of time during your everyday development in what we call the tight inner loop of editing, navigating and debugging code. If you are not on VS2015 yet, the amount of productivity features we added to that VS2015 release will have you drooling and VS2017 takes that even further.

Visual Studio 2017 includes enhancements to existing features and new features such as: Find All References re-designed for larger searches, Introducing Go To the successor to Navigate To, C++ IntelliSense Improvements – Predictive IntelliSense & Filtering, Bing Developer Assistant with C++ support, C++ Edit and Continue improvements, enhancements to the Memory diag tool, enhancements to debug visualizers, the new Exception Helper, Run to Click, Attach to Process Filter and Reattach, .editorconfig, and new Git features. You can also learn about more VS productivity improvements beyond just for C++ code.

Beyond that kind of productivity, the team focused on the fundamentals of performance in the IDE. When you build during the inner loop, where all you want is for the build to complete quickly after the edits you have just made, so that you can run/test/debug your code, the linker will save you time with 2x to 4x faster links with the on-by-default and improved fastlink option (and watch the ch9 video). Beyond build throughput, you’ll find that VS starts up faster, loads solutions faster (video), IntelliSense is faster and generally working in the IDE will truly feel faster.

vc2017_speedex

 

Smile and take credit

And last but not least, you helped us build this release with your suggestions and bug reports – thank you! In the last year, we have completed 37 C++ UserVoice items, fixed 417 bugs reported through Connect, and fixed an additional 352 feedback items. Please keep the reports coming, you can report any issues you have with Visual Studio by going to Help > Send Feedback > Report A Problem, and we take your comments very seriously – thank you again.

vc2017_feedback

In Closing

We hope you’ll love using this release as much as we liked producing it. As you can see there are so many new capabilities to take advantage of, and the goal of this summary blog post is to collect all the relevant links in one place for those of you that haven’t been following in the past year – the real content is behind the links, so scroll back up and get clicking folks.

Finding installed Visual C++ tools for Visual Studio 2017

$
0
0

There have been a number of questions from customers about how to locate the tools in the world of this new installation model.  The following blog post will share a number of options available for locating Visual Studio 2017 instances and provides various samples that illustrates the process in action.

How to find installed Visual Studio 2017 instances and C++ tools

There are multiple ways you can go about the finding the VS instances installed and determining the tools installed for each instance.

1.  vswhere.exe:   A stand-alone native executable that is redistributable and can be used to locate installed Visual Studio product instances for use in build and deployment scripts.  The tool supports emitting different formats so far including plain text, JSON, and XML.  For example, the following batch script for vswhere will find the root path the latest installed version that also contains the C++ Desktop workload:

for /r "usebackq tokens=1* delims=: " %%i in (`vswhere.exe -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop`) do (

if /i "%%i"=="installationPath" set dir=%%j

)

%dir% now contains the root installation path, if available.

2.  PowerShell API: This is the simplest API for finding VS installation instances and components, but of course requires PowerShell v3 and above.  If you are running on PowerShell v3 or v4, you will need to also install PowerShellGet.  This is already included in PowerShell v5 that comes with Windows 10.  The following command will list all installed VS2017 instances that also installed the v141 toolset for x86 and x64:

First install the VSSetup module:

Install-Module VSSetup -Scope CurrentUser

After that is completed, the following script will list all installed instances with Visual C++ compilers installed:

Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64

3.  Visual Studio Setup API: This COM API allows for querying installed VS instances and their components from a variety of programming languages (C++, C#, VB).  The code is not as simple as the PowerShell script, but we have multiple examples on GitHub of how to consume the API:

Samples on GitHub (Sample with no NuGet dependency)

Example: Finding instances with an installed Visual C++ toolset with the API

For a more specific example of using this COM API from C++ to list installed instances that include Visual C++ tools, check out this sample on GitHub.

It is inside PrintPackageReference function that my sample checks the name of each installed component in the instance to determine if the Visual C++ toolset is installed (i.e. if “Microsoft.VisualStudio.Component.VC.Tools.x86.x64” is installed).

//check if instance has VC tools
if (bstrId == L"Microsoft.VisualStudio.Component.VC.Tools.x86.x64") {
vcToolsFound = true;
std::wcout << L"Instance " << OLE2T(vcInstance) << " contains the VC++ 2017 compiler tools (x86 and x64 targets).\n";
}

If you build the solution, a simple command prompt will launch that can list installed Visual Studio instances, their components, and which instances have C++ tools installed.  To find the VC++ build tools on the machine with the tool, select option #3 in and it will indicate which instance have VC++ tools installed:1

Note:  This sample is not an official tool and is meant simply to instruct how to leverage the COM API to locate the installed Visual C++ tools.

 C++ installation workloads and components

Below is a table of the underlying names used to describe each C++ workload, as well as the underlying component names used by the installer for the options provided in each workload.  The  Visual C++ 2017 v141 compiler toolset component (x86 and x64 targeting), known as Microsoft.VisualStudio.Component.VC.Tools.x86.x64, comes included in the desktop workload as a recommended (pre-selected) component and is a required (always installed) component in the C++ game and build tools workloads.

Workload Installation Name
Desktop development with C++ Microsoft.VisualStudio.Workload.NativeDesktop
Universal Windows Platform development Microsoft.VisualStudio.Workload.Universal
Linux development with C++ Microsoft.VisualStudio.Workload.NativeCrossPlat
Game development with C++ Microsoft.VisualStudio.Workload.NativeGame
Mobile development with C++ Microsoft.VisualStudio.Workload.NativeMobile


Build Tools Workloads

MSBuild tools Microsoft.VisualStudio.Workload.MSBuildTools
Visual C++ build tools Microsoft.VisualStudio.Workload.VCTools

 

Desktop development with C++

desktop

Friendly Name Component Name
VC++ 2017 v141 toolset (x86, x64) Microsoft.VisualStudio.Component.VC.Tools.x86.x64
C++ profiling tools Microsoft.VisualStudio.Component.VC.DiagnosticTools
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Visual C++ tools for CMake Microsoft.VisualStudio.Component.VC.CMake.Project
Visual C++ ATL support Microsoft.VisualStudio.Component.VC.ATL
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
Windows XP support for C++ Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP
MFC and ATL support (x86 and x64) Microsoft.VisualStudio.Component.VC.ATLMFC
C++/CLI support Microsoft.VisualStudio.Component.VC.CLI.Support
Clang/C2 (experimental) Microsoft.VisualStudio.Component.VC.ClangC2
Standard Library Modules Microsoft.VisualStudio.Component.VC.Modules.x86.x64
IncrediBuild Component.Incredibuild
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Visual C++ 2015.3 v140 toolset (x86, x64) Microsoft.VisualStudio.Component.VC.140

 

Universal Windows Platform development

uwp

*C++ Universal Windows Platform development tools are required to be installed for C++ UWP development but are not installed by default.

Friendly Name Component Name
IntelliTrace Microsoft.VisualStudio.Component.IntelliTrace.FrontEnd
Graphics debugger and GPU profiler for DirectX Microsoft.VisualStudio.Component.Graphics.Tools
*C++ Universal Windows Platform development tools *Microsoft.VisualStudio.ComponentGroup.UWP.VC
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Architecture and analysis tools Microsoft.VisualStudio.ComponentGroup.ArchitectureTools.Managed

 

Game development with C++

game

Friendly Name Component Name
C++ profiling tools Microsoft.VisualStudio.Component.VC.DiagnosticTools
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
IncrediBuild Component.Incredibuild

 

Mobile development with C++

mobile

Friendly Name Component Name
Android NDK (RI 3B) Component.Android.NDK.R13B
Apache Ant (1.9.3) Component.Ant
Android SDK setup (API level 19 and 21) Component.Android.SDK19
Android SDK setup (API level 22) Component.Android.SDK22
Android SDK setup (API level 23) Component.Android.SDK23
Java SE Development Kit (8.0920.14) Component.JavaJDK
C++ Android development tools Component.MDD.Android
Google Android Emulator (API Level 23) Component.Android.Emulator
Intel Hardware Accelerated Execution Component.HAXM
Android NDK (RI 3B) (32bit) Component.Android.NDK.R13B_3264
Android NDK (R12B) Component.Android.NDK.R12B
Android NDK (R12B) (32bit) Component.Android.NDK.R12B_3264
Android NDK (R11C) Component.Android.NDK.R11C
Android NDK (R11C) (32bit) Component.Android.NDK.R11C_3264
C++ iOS development tools Component.MDD.IOS
IncrediBuild Component.Incredibuild

 

Visual C++ build tools

bt

*The Visual C++ Build tools always installs the VS2017 v141 toolset.

Friendly Name Component Name
*VC++ 2017 v141 toolset (x86, x64)  Microsoft.VisualStudio.Component.VC.Tools.x86.x64
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Visual C++ tools for CMake Microsoft.VisualStudio.Component.VC.CMake.Project
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
Visual C++ ATL support Microsoft.VisualStudio.Component.VC.ATL
MFC and ATL support (x86 and x64) Microsoft.VisualStudio.Component.VC.ATLMFC
C++/CLI support Microsoft.VisualStudio.Component.VC.CLI.Support
Clang/C2 (experimental) Microsoft.VisualStudio.Component.VC.ClangC2
Standard Library Modules Microsoft.VisualStudio.Component.VC.Modules.x86.x64
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240

 

Setting up your command-line environment

The Developer Command prompt in Visual Studio 2017 can be used to set the path to the VC++ toolset in the VCToolsInstallDir environment variable.  Now that we found have the path for each of the installed VS2017 instances that have VC++ compiler tools installed, we will refer to this directory as <VSInstanceDir>.  This script is in the following location:

<VsInstanceDir>\Common7\Tools\vsdevcmd.bat [-arch=<tgt_arch>] [-host_arch=<host_arch>]

<tgt_arch> is the architecture upon which the produced binary will run (x86 [default], x64, arm).

<host_arch> is the architecture for which the compiler/linker was built (i.e. do you want cl.exe/link.exe, itself, to be able to make use of 32-bit or 64-bit address space) (x86 [default], x64).

Here is an example that will set up the command-line build environment to use the host-x64 compiler targeting x64, the following command would be used:

<VsInstanceDir>\Common7\Tools\vsdevcmd.bat -arch=x64 -host_arch=x64

We have now configured our command-line build environment so that it knows where the correct VC++ tools are based on our preferences(host/target).

Identifying the VC++ compiler tools version

In a world where multiple version of VC++ tools could be installed in a single VS instance, we have introduced the concept of <VCToolsVersion> which indicates the default version of VC++ tools for that VS installation instance.  If you plan to manually assemble path to the VC++ toolset directory, we need to know the default version of the installed tools to get the full path.

The <VCToolsVersion> is found in one of two files that can be located once you have a <VSInstanceDir>.

<VsInstanceDir>\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.[txt|props]

You can check out the batch script located <VsInstanceDir>\Common7\Tools\vsdevcmd\ext\vcvars.bat as an example of how the VS Developer Command Prompt does this.

Once a <VCToolsVersion> value is identified, the full VC++ tools path can be manually constructed as follows:

<VsInstanceDir>\VC\Tools\MSVC\<VCToolsVersion>\bin\Host<host_arch>\<tgt_arch>

For our installed tools for host-x64 and target-x64, the path looks like:

<VSInstanceDir>\VC\ToolsMSVC\14.10.24930\bin\HostX64\x64

Closing remarks

Since we have removed the VS150COMNTOOLS registry key to support the new world where multiple VS instances of the same product can be installed side-by-side on the same machine, we know that many build systems and tools have relied on this in the past and the new options are not an identical replacement.  We are actively working with library developers and others with builds that depend on the VC++ compiler tools, and we are open to further feedback to help refine and improve upon the solutions mentioned above.  Please share any feedback you have in the comments or feel free to send more detailed suggestions to visualc@microsoft.com.

MSVC: The best choice for Windows

$
0
0

The C++ product team here at Microsoft offers a great C++ experience in the Visual Studio IDE, the Visual Studio Code editor, and various other tools and services. That includes the topic of this blog post: the Microsoft Visual C++ compiler and libraries toolset (MSVC).

Our goal for MSVC is to be the best compiler choice on Windows for targeting Windows, regardless of what editor or IDE you choose to use. We aim to deliver on our goal with continuous investments in the following key areas: full C++ conformance, better errors and warnings, runtime performance, reliability, build throughput, and the best security. Let’s look at each one in more detail.

The best C++ conformance

Getting to full conformance with the C++ Standard is our number one priority when it comes to our compiler. We’ve written a dedicated post discussing our road to conformance. Please go read C++ Standards Conformance from Microsoft.

Better errors and warnings

Effective compiler diagnostics are hard. We know that there are many places where our warnings and errors could improve. We’ve started small, by indicating the column number in MSVC diagnostics. But there is more targeted work to come in the area of improved diagnostics: conforming behavior for ternary operator, missing diagnostics for incorrect code, detailed continuation messages for generic error codes, better warning level configurations for system headers, and more. Look for details on this blog in the coming months.

Similarly, we’ve been making great strides in the quality and variety of warnings generated from our C++ code analysis. One good example of this is the C++ Core Guidelines checkers, which ship as part of VS 2017. These checkers are built to enforce rules in the C++ Core Guidelines, a cross-industry coding standard that helps you write code that is correct by design.

We’ve made a number of improvements recently in C++ code analysis. We’ve made improvements in the base rulesets for code analysis in VS 2017 and in the C++ Core Guidelines checkers.

Code generation and optimization (runtime performance of your code)

We have three goals in optimizing your code, and we aim to be the best in each area:

  1. Runtime performance of your code: we want it to run as fast as possible.
  2. Reliability and correctness: It doesn’t matter how fast your code is if does the wrong thing. Our first focus is reliability of the compiler and correct code generation.
  3. Security: Lots of tools search for memory vulnerabilities from “outside the box”. Our optimizer contains powerful technology to make your code safe without tools.

With regards to runtime performance, our optimization framework got a big rewrite with VS 2015 Update 3. MSVC’s new SSA (static single assignment) optimization framework opens up new possibilities for how we can make your code run faster. We’re taking advantage of this new optimization framework in VS 2017 to make your code faster.

Optimization isn’t just about speed: it’s about correctness. We test our compiler, libraries, and optimizer daily by building Windows and Office as well as more than 50 OSS projects. We also have almost a million custom-written regression tests that run with every source change checkin, full-suite testing with several hundred thousand more tests daily, and performance and throughput testing.

There are many tools that try to make your code secure from outside the box: Valgrind and address/thread sanitizers are popular examples. And there are many of these tools on Windows as well, both from Microsoft and other companies. But MSVC features powerful technologies inside the compiler that integrate security with your code. For example, Control Flow Guard, is highly-optimized security feature that combats many memory corruption vulnerabilities. We can’t talk openly our current security research but we’re always working to make your code (and ours!) safe from increasingly sophisticated attackers.

Build throughput

We’ve also greatly improved build throughput: making our compiler toolset compile your code faster. Features like /debug:fastlink in VS 2015 reduced link times by 2-4x. In VS 2017, feature improvements to /debug:fastlink give an additional 30% reduction in link time. Here are more suggestions on how to use /debug:fastlink as well as other techniques for faster build times.

How do I get the newest MSVC toolset?

The best way to get our compiler and libraries toolset is as part of the latest version of Visual Studio. Major changes to the VS installer let you install just the parts you need. You can install just the C++ workloads without having to install other languages if that’s what you prefer. You can also optionally install workloads for specific C++ scenarios.

You can even install the C++ Build Tools on your build machines without needing to install the VS IDE. These are the same tools that are installed with VS 2017 but are intended for build machines. There’s usually no need to install an IDE on a build machine because no development happens on the machines. With VS 2017 you can choose to install just the MSVC toolsetin a scriptable, standalone installer.

What if you want to check out new features that have been implemented since the last VS update? We’ve created a simple way to try out a new toolset with an easy-to-install NuGet package that installs in a C++ project or solution. We’ve also helped to get our compiler toolset integrated on the Compiler Explorer at gcc.godbolt.org, a popular web app that lets you compare compiler features and code generation across many C++ compiler toolsets.

For libraries, we’ve created a Windows-specific library package manager that lets you quickly and easily install many open source libraries directly from their repos. We started with an initial list of libraries that you suggested in a survey, plus some of the most popular libraries from GitHub. The number of supported libraries that you can install with VCPkg is always growing.

In closing

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with MSVC in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice. Thank you!

Finding installed Visual C++ tools for Visual Studio 2017

$
0
0

There have been a number of questions from customers about how to locate the tools in the world of this new installation model.  The following blog post will share a number of options available for locating Visual Studio 2017 instances and provides various samples that illustrates the process in action.

How to find installed Visual Studio 2017 instances and C++ tools

There are multiple ways you can go about the finding the VS instances installed and determining the tools installed for each instance.

1.  vswhere.exe:   A stand-alone native executable that is redistributable and can be used to locate installed Visual Studio product instances for use in build and deployment scripts.  The tool supports emitting different formats so far including plain text, JSON, and XML.  For example, the following batch script for vswhere will find the root path the latest installed version that also contains the C++ Desktop workload:

for /r "usebackq tokens=1* delims=: " %%i in (`vswhere.exe -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop`) do (

if /i "%%i"=="installationPath" set dir=%%j

)

%dir% now contains the root installation path, if available.

2.  PowerShell API: This is the simplest API for finding VS installation instances and components, but of course requires PowerShell v3 and above.  If you are running on PowerShell v3 or v4, you will need to also install PowerShellGet.  This is already included in PowerShell v5 that comes with Windows 10.  The following command will list all installed VS2017 instances that also installed the v141 toolset for x86 and x64:

First install the VSSetup module:

Install-Module VSSetup -Scope CurrentUser

After that is completed, the following script will list all installed instances with Visual C++ compilers installed:

Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64

3.  Visual Studio Setup API: This COM API allows for querying installed VS instances and their components from a variety of programming languages (C++, C#, VB).  The code is not as simple as the PowerShell script, but we have multiple examples on GitHub of how to consume the API:

Samples on GitHub (Sample with no NuGet dependency)

Example: Finding instances with an installed Visual C++ toolset with the API

For a more specific example of using this COM API from C++ to list installed instances that include Visual C++ tools, check out this sample on GitHub.

It is inside PrintPackageReference function that my sample checks the name of each installed component in the instance to determine if the Visual C++ toolset is installed (i.e. if “Microsoft.VisualStudio.Component.VC.Tools.x86.x64” is installed).

//check if instance has VC tools
if (bstrId == L"Microsoft.VisualStudio.Component.VC.Tools.x86.x64") {
vcToolsFound = true;
std::wcout << L"Instance " << OLE2T(vcInstance) << " contains the VC++ 2017 compiler tools (x86 and x64 targets).\n";
}

If you build the solution, a simple command prompt will launch that can list installed Visual Studio instances, their components, and which instances have C++ tools installed.  To find the VC++ build tools on the machine with the tool, select option #3 in and it will indicate which instance have VC++ tools installed:1

Note:  This sample is not an official tool and is meant simply to instruct how to leverage the COM API to locate the installed Visual C++ tools.

 C++ installation workloads and components

Below is a table of the underlying names used to describe each C++ workload, as well as the underlying component names used by the installer for the options provided in each workload.  The  Visual C++ 2017 v141 compiler toolset component (x86 and x64 targeting), known as Microsoft.VisualStudio.Component.VC.Tools.x86.x64, comes included in the desktop workload as a recommended (pre-selected) component and is a required (always installed) component in the C++ game and build tools workloads.

Workload Installation Name
Desktop development with C++ Microsoft.VisualStudio.Workload.NativeDesktop
Universal Windows Platform development Microsoft.VisualStudio.Workload.Universal
Linux development with C++ Microsoft.VisualStudio.Workload.NativeCrossPlat
Game development with C++ Microsoft.VisualStudio.Workload.NativeGame
Mobile development with C++ Microsoft.VisualStudio.Workload.NativeMobile


Build Tools Workloads

MSBuild tools Microsoft.VisualStudio.Workload.MSBuildTools
Visual C++ build tools Microsoft.VisualStudio.Workload.VCTools

 

Desktop development with C++

desktop

Friendly Name Component Name
VC++ 2017 v141 toolset (x86, x64) Microsoft.VisualStudio.Component.VC.Tools.x86.x64
C++ profiling tools Microsoft.VisualStudio.Component.VC.DiagnosticTools
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Visual C++ tools for CMake Microsoft.VisualStudio.Component.VC.CMake.Project
Visual C++ ATL support Microsoft.VisualStudio.Component.VC.ATL
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
Windows XP support for C++ Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP
MFC and ATL support (x86 and x64) Microsoft.VisualStudio.Component.VC.ATLMFC
C++/CLI support Microsoft.VisualStudio.Component.VC.CLI.Support
Clang/C2 (experimental) Microsoft.VisualStudio.Component.VC.ClangC2
Standard Library Modules Microsoft.VisualStudio.Component.VC.Modules.x86.x64
IncrediBuild Component.Incredibuild
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Visual C++ 2015.3 v140 toolset (x86, x64) Microsoft.VisualStudio.Component.VC.140

 

Universal Windows Platform development

uwp

*C++ Universal Windows Platform development tools are required to be installed for C++ UWP development but are not installed by default.

Friendly Name Component Name
IntelliTrace Microsoft.VisualStudio.Component.IntelliTrace.FrontEnd
Graphics debugger and GPU profiler for DirectX Microsoft.VisualStudio.Component.Graphics.Tools
*C++ Universal Windows Platform development tools *Microsoft.VisualStudio.ComponentGroup.UWP.VC
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Architecture and analysis tools Microsoft.VisualStudio.ComponentGroup.ArchitectureTools.Managed

 

Game development with C++

game

Friendly Name Component Name
C++ profiling tools Microsoft.VisualStudio.Component.VC.DiagnosticTools
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
IncrediBuild Component.Incredibuild

 

Mobile development with C++

mobile

Friendly Name Component Name
Android NDK (RI 3B) Component.Android.NDK.R13B
Apache Ant (1.9.3) Component.Ant
Android SDK setup (API level 19 and 21) Component.Android.SDK19
Android SDK setup (API level 22) Component.Android.SDK22
Android SDK setup (API level 23) Component.Android.SDK23
Java SE Development Kit (8.0920.14) Component.JavaJDK
C++ Android development tools Component.MDD.Android
Google Android Emulator (API Level 23) Component.Android.Emulator
Intel Hardware Accelerated Execution Component.HAXM
Android NDK (RI 3B) (32bit) Component.Android.NDK.R13B_3264
Android NDK (R12B) Component.Android.NDK.R12B
Android NDK (R12B) (32bit) Component.Android.NDK.R12B_3264
Android NDK (R11C) Component.Android.NDK.R11C
Android NDK (R11C) (32bit) Component.Android.NDK.R11C_3264
C++ iOS development tools Component.MDD.IOS
IncrediBuild Component.Incredibuild

 

Visual C++ build tools

bt

*The Visual C++ Build tools always installs the VS2017 v141 toolset.

Friendly Name Component Name
*VC++ 2017 v141 toolset (x86, x64)  Microsoft.VisualStudio.Component.VC.Tools.x86.x64
Windows 10 SDK (10.0.14393.0) Microsoft.VisualStudio.Component.Windows10SDK.14393
Visual C++ tools for CMake Microsoft.VisualStudio.Component.VC.CMake.Project
Windows 8.1 SDK And UCRT SDK Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
Visual C++ ATL support Microsoft.VisualStudio.Component.VC.ATL
MFC and ATL support (x86 and x64) Microsoft.VisualStudio.Component.VC.ATLMFC
C++/CLI support Microsoft.VisualStudio.Component.VC.CLI.Support
Clang/C2 (experimental) Microsoft.VisualStudio.Component.VC.ClangC2
Standard Library Modules Microsoft.VisualStudio.Component.VC.Modules.x86.x64
Windows 10 SDK (10.0.10586.0) Microsoft.VisualStudio.Component.Windows10SDK.10586
Windows 10 SDK (10.0.10240.0) Microsoft.VisualStudio.Component.Windows10SDK.10240

 

Setting up your command-line environment

The Developer Command prompt in Visual Studio 2017 can be used to set the path to the VC++ toolset in the VCToolsInstallDir environment variable.  Now that we found have the path for each of the installed VS2017 instances that have VC++ compiler tools installed, we will refer to this directory as <VSInstanceDir>.  This script is in the following location:

<VsInstanceDir>\Common7\Tools\vsdevcmd.bat [-arch=<tgt_arch>] [-host_arch=<host_arch>]

<tgt_arch> is the architecture upon which the produced binary will run (x86 [default], x64, arm).

<host_arch> is the architecture for which the compiler/linker was built (i.e. do you want cl.exe/link.exe, itself, to be able to make use of 32-bit or 64-bit address space) (x86 [default], x64).

Here is an example that will set up the command-line build environment to use the host-x64 compiler targeting x64, the following command would be used:

<VsInstanceDir>\Common7\Tools\vsdevcmd.bat -arch=x64 -host_arch=x64

We have now configured our command-line build environment so that it knows where the correct VC++ tools are based on our preferences(host/target).

Identifying the VC++ compiler tools version

In a world where multiple version of VC++ tools could be installed in a single VS instance, we have introduced the concept of <VCToolsVersion> which indicates the default version of VC++ tools for that VS installation instance.  If you plan to manually assemble path to the VC++ toolset directory, we need to know the default version of the installed tools to get the full path.

The <VCToolsVersion> is found in one of two files that can be located once you have a <VSInstanceDir>.

<VsInstanceDir>\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.[txt|props]

You can check out the batch script located <VsInstanceDir>\Common7\Tools\vsdevcmd\ext\vcvars.bat as an example of how the VS Developer Command Prompt does this.

Once a <VCToolsVersion> value is identified, the full VC++ tools path can be manually constructed as follows:

<VsInstanceDir>\VC\Tools\MSVC\<VCToolsVersion>\bin\Host<host_arch>\<tgt_arch>

For our installed tools for host-x64 and target-x64, the path looks like:

<VSInstanceDir>\VC\ToolsMSVC\14.10.24930\bin\HostX64\x64

Closing remarks

Since we have removed the VS150COMNTOOLS registry key to support the new world where multiple VS instances of the same product can be installed side-by-side on the same machine, we know that many build systems and tools have relied on this in the past and the new options are not an identical replacement.  We are actively working with library developers and others with builds that depend on the VC++ compiler tools, and we are open to further feedback to help refine and improve upon the solutions mentioned above.  Please share any feedback you have in the comments or feel free to send more detailed suggestions to visualc@microsoft.com.

What’s new with IncrediBuild and Visual Studio 2017

$
0
0

As a part of Visual Studio 2015 release, we introduced a partnership between IncrediBuild and Visual Studio. This partnership allowed developers to install IncrediBuild from the Build Accelerator menu and benefit from a few key build acceleration features free of charge.

Based upon the feedback we have heard, with Visual Studio 2017, we have made some changes to this experience which are as follows.

Install IncrediBuild from the Visual Studio Installer

Once you have downloaded the Visual Studio 2017 installer, IncrediBuild is presented as an optional component for C++ workloads namely ‘Desktop development with C++’, ‘Mobile development with C++’ and ‘Game development with C++’.

The figure below depicts the IncrediBuild optional component presented as part of the ‘Desktop Development with C++ workload’.

incredibuild

To install IncrediBuild just check the IncrediBuild optional component and then just wait and watch.

It should not take too long for the installation to complete and once it has been completed you can go ahead and build your first C++ application with IncrediBuild and Visual Studio 2017.

Increased Parallelization for your builds

Another change we have made with Visual Studio 2017 release is that the IncrediBuild build engine will now parallelize your build for up to 16 cores vs. the 8 cores limit in Visual Studio 2015 at no additional cost This would help further improve your build time when using IncrediBuild with Visual Studio 2017.

Tell us what you think

Download Visual Studio 2017, try out the IncrediBuild Visual Studio integration, and let us know what you think. You can report problems by clicking the user feedback icon next to Quick Launch in the title bar and then selecting . Track your feedback on the developer community portal. For suggestions, let us know through User Voice. We look forward to hearing from you!

 

MSVC: The best choice for Windows

$
0
0

The C++ product team here at Microsoft offers a great C++ experience in the Visual Studio IDE, the Visual Studio Code editor, and various other tools and services. That includes the topic of this blog post: the Microsoft Visual C++ compiler and libraries toolset (MSVC).

Our goal for MSVC is to be the best compiler choice on Windows for targeting Windows, regardless of what editor or IDE you choose to use. We aim to deliver on our goal with continuous investments in the following key areas: full C++ conformance, better errors and warnings, runtime performance, reliability, build throughput, and the best security. Let’s look at each one in more detail.

The best C++ conformance

Getting to full conformance with the C++ Standard is our number one priority when it comes to our compiler. We’ve written a dedicated post discussing our road to conformance. Please go read C++ Standards Conformance from Microsoft.

Better errors and warnings

Effective compiler diagnostics are hard. We know that there are many places where our warnings and errors could improve. We’ve started small, by indicating the column number in MSVC diagnostics. But there is more targeted work to come in the area of improved diagnostics: conforming behavior for ternary operator, missing diagnostics for incorrect code, detailed continuation messages for generic error codes, better warning level configurations for system headers, and more. Look for details on this blog in the coming months.

Similarly, we’ve been making great strides in the quality and variety of warnings generated from our C++ code analysis. One good example of this is the C++ Core Guidelines checkers, which ship as part of VS 2017. These checkers are built to enforce rules in the C++ Core Guidelines, a cross-industry coding standard that helps you write code that is correct by design.

We’ve made a number of improvements recently in C++ code analysis. We’ve made improvements in the base rulesets for code analysis in VS 2017 and in the C++ Core Guidelines checkers.

Code generation and optimization (runtime performance of your code)

We have three goals in optimizing your code, and we aim to be the best in each area:

  1. Runtime performance of your code: we want it to run as fast as possible.
  2. Reliability and correctness: It doesn’t matter how fast your code is if does the wrong thing. Our first focus is reliability of the compiler and correct code generation.
  3. Security: Lots of tools search for memory vulnerabilities from “outside the box”. Our optimizer contains powerful technology to make your code safe without tools.

With regards to runtime performance, our optimization framework got a big rewrite with VS 2015 Update 3. MSVC’s new SSA (static single assignment) optimization framework opens up new possibilities for how we can make your code run faster. We’re taking advantage of this new optimization framework in VS 2017 to make your code faster.

Optimization isn’t just about speed: it’s about correctness. We test our compiler, libraries, and optimizer daily by building Windows and Office as well as more than 50 OSS projects. We also have almost a million custom-written regression tests that run with every source change checkin, full-suite testing with several hundred thousand more tests daily, and performance and throughput testing.

There are many tools that try to make your code secure from outside the box: Valgrind and address/thread sanitizers are popular examples. And there are many of these tools on Windows as well, both from Microsoft and other companies. But MSVC features powerful technologies inside the compiler that integrate security with your code. For example, Control Flow Guard, is highly-optimized security feature that combats many memory corruption vulnerabilities. We can’t talk openly our current security research but we’re always working to make your code (and ours!) safe from increasingly sophisticated attackers.

Build throughput

We’ve also greatly improved build throughput: making our compiler toolset compile your code faster. Features like /debug:fastlink in VS 2015 reduced link times by 2-4x. In VS 2017, feature improvements to /debug:fastlink give an additional 30% reduction in link time. Here are more suggestions on how to use /debug:fastlink as well as other techniques for faster build times.

How do I get the newest MSVC toolset?

The best way to get our compiler and libraries toolset is as part of the latest version of Visual Studio. Major changes to the VS installer let you install just the parts you need. You can install just the C++ workloads without having to install other languages if that’s what you prefer. You can also optionally install workloads for specific C++ scenarios.

You can even install the C++ Build Tools on your build machines without needing to install the VS IDE. These are the same tools that are installed with VS 2017 but are intended for build machines. There’s usually no need to install an IDE on a build machine because no development happens on the machines. With VS 2017 you can choose to install just the MSVC toolsetin a scriptable, standalone installer.

What if you want to check out new features that have been implemented since the last VS update? We’ve created a simple way to try out a new toolset with an easy-to-install NuGet package that installs in a C++ project or solution. We’ve also helped to get our compiler toolset integrated on the Compiler Explorer at gcc.godbolt.org, a popular web app that lets you compare compiler features and code generation across many C++ compiler toolsets.

For libraries, we’ve created a Windows-specific library package manager that lets you quickly and easily install many open source libraries directly from their repos. We started with an initial list of libraries that you suggested in a survey, plus some of the most popular libraries from GitHub. The number of supported libraries that you can install with VCPkg is always growing.

In closing

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with MSVC in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. For suggestions, let us know through UserVoice. Thank you!


Visual Studio for Teams of C++ Developers

$
0
0

In this blog post we will dive into how Visual Studio supports teams of C and C++ developers. We’ll begin by creating a small C++ program and placing it in a Git repository in Visual Studio Team Services. Next we’ll see how to commit and push updates and get updates from others. Finally, we will work with GitHub repos using the GitHub extension for Visual Studio.

Adding an Existing C++ Project to Git in Visual Studio Team Services

In this example, you will create a small sample application and use Visual Studio to create a Git repository in Visual Studio Team Services. If you have an existing project, you can use it instead.

To get started you’ll need an account on Visual Studio Team Services. Sign up for a free Visual Studio Team Services account. You can use a personal, work or school account. During the process, a new default project may be created but will not be used in this example.

  1. Download the sample project from and unzip it into a suitable working directory. You can also use one of your own C++ projects; the steps will be the same.
  2. Start Visual Studio 2017 and load the CalculatingWithUnknowns solution. Expand the Source Files node in Solution Explorer to see the solution files:
    Visual Studio Solution Explorer showing project C++ source files
  3. The blue status bar at the bottom of the Visual Studio window is where you perform Git-related tasks. Create a new local Git repo for your project by selecting Add to Source Control in the status bar and then selecting Git from the . This will create a new repo in the folder the solution is in and commit your code into that repo.
  4. You can select items in the status bar to quickly navigate between Git tasks in Team Explorer.
    Status bar showing four different Git tasks
    1. Up-arrow with two shows the number of unpublished commits in your local branch. Selecting this will open the Sync view in Team Explorer.
    2. Pencil with 0 shows the number of uncommitted file changes. Selecting this will open the Changes view in Team Explorer.
    3. Current repo is CalculatingWithUnknowns  shows the current Git repo. Selecting this will open the Connect view in Team Explorer.
    4. Current Git branch is master shows your current Git branch. Selecting this displays a branch picker to quickly switch between Git branches or create new branches.
  5. In the Sync view in Team Explorer, select the Publish Git Repo button under Publish to Visual Studio Team Services.
    Sync view in Team Explorer with Publish Git Repo button highlighted in red
  6. Verify your email and select your account in the Account Url drop down. Enter your repository name (or accept the default, in this case CalculatingWithUnknowns) and select Publish Repository. Your code is now in a Team Services repo. You can view your code on the web by selecting See it on the web.

As you write your code, your changes are automatically tracked by Visual Studio. Continue to the next section if you want to learn how to commit and track changes to code, push your changes and sync and get changes from other team members. You can also configure your C++ project for continuous integration (CI) with Visual Studio Team Services.

Team Explorer Home dialog highlighting the example, CalculatingWithUnknowns C++ project, was pushed and you can see it on the web.

Commit and Push Updates and Get Updates from Others

Code change is inevitable. Fortunately, Visual Studio 2017 makes it easy to connect to repositories like Git hosted in Visual Studio Team Services or elsewhere and make changes and get updates from other developers on your team.

These examples use the same project you configured in the previous section. To commit and push updates:

  1. Make changes to your project. You can modify code, change settings, edit text files or change other files associated with the project and stored in the repository – Visual Studio will automatically track changes. You can view changes by right-clicking on a file in Solution Explorer then clicking View History, Compare with Unmodified, and/or Blame (Annotate).

C++ source file differences in CalculatingWithUnknowns.cpp.

  1. Commit changes to your local Git repository by selecting the pending changes icon from the status bar.

Status bar showing one pending change in the C++ project

  1. On the Changes view in Team Explorer, add a message describing your update and commit your changes.

Team Explore Changes dialog with a branch comment and the Commit All button highlighted

  1. Select the unpublished changes status bar icon or the Sync view in Team Explorer. Select Push to update your code in Team Services/TFS.

To sync your local repo with changes from your team as they make updates:

  1. From the Sync view in Team Explorer, fetch the commits that your team has made. Double-click a commit to view its file changes.
  2. Select Sync to merge the fetched commits into your local repo and then push any unpublished changes to Team Services.
  3. The changes from your team are now in your local repo and visible in Visual Studio.

Work with GitHub repos using the GitHub Extension for Visual Studio

The GitHub Extension for Visual Studio is the easiest way to connect your GitHub repositories in Visual Studio. With the GitHub Extension, you can clone repos in one click, create repositories and clone it in Visual Studio in one step, publish local work to GitHub, create and view pull requests in Visual Studio, create gists and more.

In this section, we walk through installation, connecting to GitHub and cloning a repo.

  1. Install the GitHub Extension for Visual Studio. If you already have Visual Studio installed without the extension, you can install the GitHub Extension it from the Visual Studio GitHub site. You can also select it as part of the Visual Studio installation process. To install (or modify) with Visual Studio 2017, run the installer and click Individual components and then click GitHub extension for Visual Studio under Code tools, then proceed with other selections and installation (or modification):

Individual components in the installer with GitHub extension for Visual Studio selected

  1. On the Connect view of Team Explorer, expand the GitHub connection and select Sign In. Provide your GitHub credentials to complete sign in.

Team Explorer Connect dialog with GitHub options including sign-in

  1. Click Clone to bring up a dialog that shows all the repositories you can access. If you want to clone one, select it and then click Clone.
  2. To create a new repo, click Create and provide information about the repository. You can choose among several Git ignore preferences and licenses and choose whether your repo is public or private. If you have a private account, you will be restricted to private repositories.

Create a GitHub Repository dialog

  1. To publish an existing project on your machine, click on the Sync tab in the Team Explorer window to get to the Publish to GitHub

To learn more about the extension, visit the GitHub Extension for Visual Studio page.

 

C++ Debugging and Diagnostics

$
0
0

Debugging is one of the cornerstones of software development, and it can consume a significant portion of a developer’s day.  The Visual Studio native debugger provides a powerful and feature-rich experience for finding and fixing problems that arise in your applications, no matter the type of problem or how difficult it is to solve.  In fact, there are so many debugging features and tools inside Visual Studio that it can be a bit overwhelming for new users.  This blog is meant to give you a quick tour of the Visual Studio native debugger and how it can help you in all areas of your C++ development.

Table of Contents

Breakpoints and control flow

After you have built your application in Visual Studio, you can start the debugger simply by pressing F5.  When you start debugging, there are several commands that can help you to navigate the breakpoints in your application so that you can control the state of the program and the current context of the debugger.  These commands give you flexible control over the debugger’s scope and what lines and functions of code you want to investigate.

  • Continue with [F5]: Run to the next break point.
  • Step over [F10]: Run the next line of code and then break.
  • Step into [F11]: Step into the function called on the current line of code.
  • Step out [Shift+F11]: Step out of the current function and break at the next executable line after the function call.

When hovering over a breakpoint in your code, you will see two icons appear.  The icon on the right with two circles allows you to quickly toggle the current breakpoint on or off without losing the breakpoint marker at this line of code:

breakpoint

The icon on the left will launch the list of breakpoint options. Here you can add conditions or actions to a breakpoint.

bpmenu

Sometimes you want a breakpoint to be hit only when a certain condition is satisfied, like x<=5 is true where x is a variable in the debugger scope.  Conditional breakpoints can easily be set in Visual Studio using the inline breakpoint settings window, which allows you to conveniently add conditional breakpoints to your code directly in the source viewer without requiring a modal window.  Notice that conditional breakpoints contain a “+” sign to indicate at least one condition has been added to the breakpoint.

inlinebp

There is also a set of breakpoint actions that can be performed at a breakpoint, like printing the process ID or the call stack. Visual Studio also refers to these as breakpoint actions as “tracepoints”.  The inline breakpoint settings window allows you to set a variety of breakpoint actions such as printing the call stack or PID.  Notice that when at least one action is assigned to a breakpoint, the breakpoint appears as a diamond shape.  In the example below, we have added both a condition and an action to the breakpoint; this makes it appear as a diamond with a “+” sign inside.

inlinebp2

Function breakpoints (watch points) will activate when a specified function is encountered by the debugger.  Use the Debug menu and select New breakpoint to add a function breakpoint.

functionbp

Data breakpoints will stop the debugger when a specific address is hit during debugging.  Use the Debug menu and select New breakpoint to add a function breakpoint.

Data inspection and visualization

When you are stopped at a breakpoint, the debugger has access to the variable names and values that are currently stored in memory.  There are several windows that allow you to view the contents of these objects.

  • Locals: The locals window lists all variables currently within the debugger scope, which typically includes all static and dynamic allocations made so far in the current function.
  • Autos: This window provides a list of the variables in memory that originate from:
    • The current line at which the breakpoint is set.
      • Note that in the example below, line 79 has yet to execute. The variable is not yet initialized and there is no value for the Autos window to display.
  • The previous 3 lines of code. As you can see below, when we are at the breakpoint on line 79, the previous three lines are shown, and the current line awaiting execution has been detected, but the value is not yet available until this line executes.

code1

autos

  • Watch: These windows allows you to track variables of interest as you debug your application. Values are only available when the listed variables are in the scope of the debugger.
  • Quick Watch is designed for viewing the variable contents without storing it in the Watch window for later viewing. Since the dialog is modal, it is not the best choice for tracking a variable over the entire debugging session: for cases like this the Watch window is preferable.

quickwatch

  • Memory windows: These provide a more direct view of system memory and are not restricted to what is currently shown in the debugger. They provide the ability to arrange values by bit count, for example 16, 32, and 64. This window is intended primarily for viewing raw unformatted memory contents. Viewing custom data types is not supported here.

memorywindow

Custom Views of Memory

Visual Studio provides the Natvis framework, which enables you to customize the way in which non-primitive native data types are displayed in the variable windows (Locals, Autos, Watches).  We ship Natvis visualizers for our libraries, including the Visual C++ STL, ATL, and MFC.  It is also easy to create your own Natvis visualizer to customize the way a variable’s contents are displayed in the debugger windows mentioned above.

Creating a Natvis File

You can add natvis files to a project or as a top-level solution item for .exe projects.  The debugger consumes natvis files that are in a project/solution.  We provide a built-in template under Visual C++ –> Utility folder for creating a .natvis file.

newnatvis

This will add the visualizer to your project for easier tracking and storage via source control.

solnexp

For more information on how to write .natvis visualizers, consult the Natvis documentation.

Modifying Natvis Visualizers While Debugging

The following animation shows how editing a natvis for the Volcano type will change the debugger display  inthe variable windows.  The top-level display string for the object is changed the to show the m_nativeName instead of the m_EnglishName.  Notice how the changes to the .natvis file are immediately picked up by the debugger and the difference is shown in red text. natvisedit

Diagnostic tools and performance profiling

Most profiling tools run in a special mode that is separate from the debugger itself.  In Visual Studio, we have added a set of performance and diagnostics tools that can run during debugging and provide more insight into the performance and state of your apps. You can control the flow of the application to get to a problem area and then activate more powerful tools as you drill down into the problem.  Instead of waiting around for the problem to happen, you are able to have full control of the program and decide what information you want to analyze, whether it’s how much time a function spends on the CPU, or viewing the memory usage of each allocation by type. The live CPU and memory usage of your application are displayed in the graph and debugger event are indicated along the timeline. There is a tab for using each of the included diagnostic tools: CPU Usage and Memory Usage.

dtwindow

CPU Usage

This tool allows you to view the CPU usage for each function called in a selected time range on the CPU graph.  You must enable the tools by clicking the “CPU Profiling” button on the left of this tab in order to select a time range for analysis.

cpuusage

Memory Usage

This tool enables you to use the memory profiler, which for native profiling must be enabled using the Heap Profiling button so that you can capture heap snapshots.  The button on the left takes a snapshot and you can view the contents of each snapshot by clicking the blue links in the snapshot table.

snapshotreel

The Types View shows the types that were resolved from the memory snapshot including the count and total memory footprint.  You can navigate to the Instances View by double-clicking a line in this view.

typesview

The Instances View shows the types that were resolved from the memory snapshot including the count and total memory footprint.  You can navigate to the Instances View by double-clicking a line in this view.  You can navigate back to the types view using the back arrow to the left of the type name.

instancesview

The Stacks View shows the call stack for your program and allows you to navigate through the call path of each captured allocation.  You can navigate to the stacks view from the types view by selecting Stacks View in the View Mode dropdown.  The top section of this page shows the full execution call stack and can be sorted by callee or caller (in-order or reverse) with the control at the top right called Aggregate call stack by.  The lower section will list all allocation attributable to the selected part of the call stack.  Expanding these allocations will show their allocation call stack.

stacksview

Debugging processes and devices

Attaching to Process

Any process running on your Windows machine can be debugged using Visual Studio.  If you want to view the variable types, make sure to have the debug symbols loaded for the process that you are attaching to.

attach

Remote Debugging

To remotely debug into another machine that you can connect to via your network, enable the remote debugger via the debugger dropdown.  This allows you to debug into a machine no matter how far away it is, as long as you can connect to it over a network.  You can also easily debug applications running on external devices such as a Surface tablet.

debugselector

The IP address and connection details can be managed in the debugger property page, accessed using either Alt+Enter or right-clicking the project in the Solution Explorer.

debugpp

Multi-threaded debugging

Visual Studio provides several powerful windows to help debugging multi-threaded applications.  The Parallel Stacks window is useful when you are debugging multithreaded applications. Its Threads View shows call stack information for all the threads in your application. It lets you navigate between threads and stack frames on those threads. In native code, the Tasks View shows call stacks of task groupsparallel algorithmsasynchronous agents, and lightweight tasks.

parallelstacks

There is also a Parallel Watch window designed specifically for tracking variables across different threads, showing each thread as a row and each watch (object) as a column.  You can also evaluate boolean expressions on the data and export the data to spreadsheet (.csv or Excel) for further analysis.

parallelthreads

Edit and continue

Edit and continue allows you to edit some sections of your code during a debugging session without rebuilding, potentially saving a lot of development time.  This is enabled by default, and can be toggled or customized using the Debugging options, accessible via the Debug menu and selecting Options.

enc

Other resources

If you are interested in some more content and videos about debugging in Visual Studio, check out these links:

Blog posts

Related documentation

Videos

Linux development with C++ in Visual Studio

$
0
0

C++ is a versatile language that is used in many domains, and on many platforms. Visual Studio enables you, as a C++ developer, to target Windows desktop, Windows Store, Linux, Mobile (Android and iOS), and also gaming platforms like DirectX, Unreal, and Cocos. We call all these “workloads”, and those of you using other programming languages like Python or C# can target other workloads in Visual Studio. We know C++ developers have other tooling options when it comes to targeting any of those workloads, so why do so many choose Visual Studio to do so? In terms of the number of users, Visual Studio has long been the leading IDE on Windows for C++ developers targeting any platform, and that is because many of you enjoy the quality of its excellent editing environment, market leading debugging and diagnostic tools, great testing tools, useful team collaboration tools, as well as the ability to bring your own compiler/build system.

You can click any of the links above to learn about the corresponding capabilities in Visual Studio. A great starting point is our quick guide to Getting Started with Visual Studio.

In this blog post we will dive into the Linux Development with C++ workload. You will learn

  • how to acquire this as part of installing Visual Studio 2017,
  • how to create a Linux C++ project,
  • how to establish your first connection to a Linux machine from Visual Studio,
  • how sources are managed between Visual Studio and Linux,
  • what capabilities the Linux project system provides,
  • and how to use Visual Studio diagnostic tools to find and resolve issues.

Install Workload for Linux development with C++

Visual Studio 2017 introduces the C/C++ Linux Development workload. To install it, start the Visual Studio installer and choose to either install or modify an existing installation. Scroll to the bottom. Under the section “Other Toolsets” you will find Linux Development with C++. The workload installs in under 10 minutes.

Linux Workload

Opening projects

You will need a Linux machine, of course, or you can use the Windows Subsystem for Linux with Visual Studio. You can use any Linux distribution that has SSH, gdbserver, and a compiler installed. In your Linux environment, this is as easy as:

sudo apt install -y build-essential gdbserver

To create a new Linux Console Application in Visual Studio, select that project type under New Project > Visual C++ > Cross Platform > Linux.

Linux Projects

This project will open a readme with some instructions about its capabilities. There is also a main.cpp file which outputs text to the console. Go ahead and compile it using the menu Build > Build Solution. Since this is your first Linux project you will be prompted by the connection manager dialog to add a connection. You can add new connections with either password or private key authentication.

Linux Connection Manager

After you enter your information, Visual Studio manages the connection to your Linux system where builds are performed.  If there are any problems, the build output points you directly to issues found in your code.

The project system synchronizes your sources between Windows and Linux, and provides you with extensive control to manage this yourself if you need it. Right click on the project in Solution Explorer and choose Properties. The General property page allows you to set options like what folders to use on the remote system and what the Configuration Type is for your output (an executable, static or dynamic library). The Debugging page provides additional control over execution; for example, you can run additional commands before launching a program such as exporting the display to debug desktop apps. The VC++ Directories page provides options for controlling IntelliSense by providing additional directories to include or exclude. The Copy Sources property page allows you to specify whether to copy sources to the remote Linux system. You may not want to copy sources if you are working with a share or are managing your own synchronization through other means. The C/C++ and Linker property page groups provide many options for controlling what flags are passed to the compiler. They also enable you to override the default setting to use g++ and specify your own. Finally, the Build Events property page group provides the capability to run additional commands locally or remotely as part of the build process.

Linux Project Properties

Of course, you probably already have some existing sources, and probably a build system as well. If that is the case, our makefile project is what you want. You can create one from the New Project dialog, then import your sources, and then specify the build commands to use on the remote Linux system. If your project is particularly large, you may find it easier to auto-generate the project files instead of configuring everything manually with the property pages. You can find some example scripts on GitHub that show you how to generate Linux makefile projects for Visual Studio based on an existing source base. These examples should be easy to modify for your own requirements.

Use the full power of Visual Studio productivity features with your Linux C++ code

IntelliSense is provided out of the box for GCC and libstdc++. It is easy to configure your project to use headers from your own Linux system to enable IntelliSense for everything you need. Once you get going with your own code you can really see Visual Studio’s productivity features in action.

Member list and Quick Info, shown in the screenshot below, are just two examples of the powerful IntelliSense features that make writing code easier and faster. Member list shows you a list of valid members from a type or namespace. Typing in “->” following an object instance in the C++ code will display a list of members, and you can insert the selected member into your code by pressing TAB, or by typing a space or a period. Quick Info displays the complete declaration for any identifier in your code. In the example in the screenshot, Visual Studio is showing the list of accessible members of the SimpleServer object and the declaration of the open method, making writing code a lot easier.

Linux Code Editing

Refactoring, autocomplete, squiggles, reference highlighting, syntax colorization, and code snippets are some of the other useful productivity features that are helpful when you are writing and editing your code.

Navigating in large codebases and jumping between multiple code files can be a tiring task. Visual Studio offers many great code navigation features, including Go To Definition, Go To Line/Symbols/Members/Types, Find All References, View Call Hierarchy, Object Browser, and many more, to boost your productivity.

The Peek Definition feature, as shown in the screenshot below, shows the definition inline without switching away from the code that you’re currently editing. You can find Peek Definition by placing the insertion point on a method that you want to explore and then right-clicking or pressing Alt+F12. In the screenshot below, the definition of the OpenCV face detection detectMultiScale method, in objdetect.hpp, is shown in an embedded window in the current cpp file, making reading and writing OpenCV code more efficient.

Linux Peek Definition

You can learn much more about editing and navigating C++ code in Visual Studio here.

Debugging and diagnosing issues

Visual Studio excels at helping you solve your development problems, and now you can use those capabilities with your C++ code on Linux. You can set breakpoints in your C++ code and press F5 to launch the debugger, which will run your code on your Linux machine. When a breakpoint is hit, you can watch the value of variables and complex expressions in the Autos and Watch tool windows as well as in the data tips on mouse hovering, view the call stack in the Call Stack window, and step in and step out of your code easily. You can also use conditions in your breakpoints to narrow in on specific problems. You can also set actions, for example to record variable values to the output window. You can also inspect application threads or view disassembly.

If you need to interact with your programs on Linux you can use the Linux Console window from within Visual Studio. To activate this window, use the menu Debug > Linux Console. In the screenshot below you can see input being provided to the scanf call on line 24.

Linux Console Window

You can even attach to processes on your Linux machines to debug problems live. Open the Debug menu and select Attach to Process. As shown in the screenshot below select the SSH Connection type. You can then use the drop-down target menu to select a Linux machine. This will then enumerate the remote connections you have previously created.

Linux Attach to Process

See our debugging and diagnostics with C++ page to learn more about our general capabilities.

Working with others

Developing an application usually involves working with others. When it comes to source code storing and sharing and cloud build, Visual Studio Team Services have you covered. Collaborating with other team members is as easy as signing up for a free Visual Studio Team Services account, checking in your source code, and specifying who has access to it. Now everyone on your team can check out source code, edit it, and check it back in.

Visual Studio Team Services also simplifies continuous integrations for your code. Create and manage build processes that automatically compile and test your games in the cloud. Wondering if a bug was fixed in this build? By associating work items with code, the work items are listed in the build summary along with code changes and test results.

We have more information available about developing C++ applications in a team.

Get started with Visual Studio Linux C/C++ Development today

Learn in depth how to use the Visual Studio for C/C++ Linux Development in our announcement post and on docs.microsoft.com. Please provide feedback from within Visual Studio by selecting Help > Send Feedback. If you have any questions you can send us email at VC++ Linux Support.

DirectX game development with C++ in Visual Studio

$
0
0

Leverage the full power of C++ to build high-end games powered by DirectX to run on a variety of devices in the Windows family, including desktops, tablets, and phones. In this blog post we will dive into DirectX development with C++ in Visual Studio. First we’ll look at how to acquire the tools needed for DirectX desktop and Universal Windows Platform (UWP) development, then we will get started with a built-in project template, followed by writing C++ code and HLSL (High Level Shader Language) shaders for the DirectX game. Next we will use the world-class Visual Studio debugger and the Visual Studio DirectX graphics debugger and profiler to catch and fix issues in the code. Finally, we will talk about how to test your DirectX game and collaborate with your team members using Visual Studio.

Install Visual Studio for DirectX development

First, download Visual Studio 2017 and launch the Visual Studio installer.

To build DirectX desktop games, choose the “Game development with C++” workload under the “Mobile & Gaming” category. This workload gives you the core tools to build DirectX games for desktop, which includes the Visual Studio core editor, Visual C++ compiler, Windows Universal C Runtime, and Visual Studio debugger.

1-install-vs2017

The pre-selected components are highly recommended. Here are the two recommended components and the rest of the optional components that are useful for building DirectX games:

  • C++ profiling tools: includes Graphics Diagnostics for DirectX (a.k.a. Visual Studio graphics debugger) and a set of profiling tools for memory, CPU and GPU. Selected by default.
  • Windows 10 SDKs: The latest Windows 10 SDK is selected by default.
  • Windows 8.1 SDK and UCRT (Universal C Runtime) SDK
  • IncrediBuild: installs IncrediBuild from incredibuild.com, a distributed computing solution for code builds, data builds and development tasks.
  • Cocos: installs Cocos Creator from cocos2d-x.org, the editor for building Cocos2d games.
  • Unreal Engine installer: installs Epic Games Launcher from unrealengine.com, which you can use to download and install the Unreal Engine.

If you’re also interested in building DirectX games for UWP to run on a variety of devices in the Windows family, you can install the tools by checking the “Universal Windows Platform development” workload under the “Windows” category with the “C++ Universal Windows Platform tools” option selected. The C++ UWP component adds the core C++ UWP support and 3 DirectX project templates for DirectX11 and DirectX12 to get you started quickly. The “Graphics debugger and GPU profiler” component is highly recommended for DirectX development, as it brings in the Graphics Diagnostics feature for DirectX graphics debugging and GPU Usage feature for profiling GPU and CPU usage in DirectX games.

2-install-uwp

Getting started

DirectX game for UWP

The UWP workload comes with 3 DirectX project templates. Use the menu item New->Project to launch the New Project dialog and then type “DirectX” in the search box in the upper right corner to find the project templates for DirectX: DirectX11 App, DirectX12 App, DirectX11 and XAML App. Select one template and click OK.

3-templates

After the project is created, you’re all set to run the DirectX app right away by pressing F5 or clicking Debug->Start with debugging from the menu. You should see a colored 3D cube spinning on your screen.

DirectX game for desktop

To build a DirectX desktop app, you can either start with the Win32 Project template in the New Project dialog or download a sample from DirectX11 samples or DirectX12 samples as a starting point.

Write C++ code with the full power of the Visual Studio IDE

Now we have a basic 3D app running, it’s time to add game logic in C++. Use the full power of Visual Studio productivity features, including IntelliSense and code navigation, to write your game code in C++.

Member list and Quick Info, as shown in the following screenshot, are just two examples of the IntelliSense features Visual Studio offers to make code writing easier and faster. Member list shows you a list of valid members from a type or namespace. Typing in “->” following an object instance in the C++ code will display a list of members, and you can insert the selected member into your code by pressing TAB, or by typing a space or a period. Quick Info displays the complete declaration for any identifier in your code. In the following screenshot, Visual Studio is showing the list of members of an instance of the DX::DeviceResources object and the declaration of the GetBackBufferRendererTargetView method, making writing DirectX code a lot easier.

4-editing

Refactoring, Auto-complete, squiggles, reference highlighting, syntax colorization, code snippets are some of the other useful productivity features to be of great assistance in code writing and editing.

Navigating in large codebases and jumping between multiple code files can be a tiring task. Visual Studio offers many great code navigation features, including Go To Definition, Go To Line/Symbols/Members/Types, Find All References, View Call Hierarchy, Object Browser, and many more, to boost your productivity.

The Peek Definition feature, as shown in the following screenshot, brings the definition to the current code file, allows viewing and editing code without switching away from the code that you’re writing. You can find Peek Definition by opening the context menu on right click or shortcut Alt+F12 for a method that you want to explore. In the example in the screenshot, Visual Studio brings in the definition of the CreateInputLayout method that lives in the d3d1.h file as an embedded window into the current cpp file, making reading and writing DirectX code more efficiently.

5-navigation

Write and debug shaders

Besides C++ code, writing shader code is another big part of building DirectX games. The Visual Studio shader editor recognizes HLSL, FX, and other types of shader files, and provides syntax highlighting and braces auto-completion, making it easier to read and write shader code. Debugging shader code from a captured frame is another great way to pinpoint the source of rendering problems. Simply set a breakpoint in your shader code and press F5 to debug it. You can inspect variables and expressions in Locals and Autos windows. Learn more about the HLSL Shader Debugger.

6-shader

Debug C++ code with the world-class Visual Studio debugger

Troubleshooting issues in the code can be time-consuming. Use the Visual Studio debugger to help find and fix issues faster. Set breakpoints in your C++ code and press F5 to launch the debugger. When the breakpoint is hit, you can watch the value of variables and complex expressions in the Autos and Watch windows as well as in the data tips on mouse hover, view the call stack in the Call Stack window, and step in and step out of the functions easily. In the example in the screenshot below, the Autos window is showing us the data in the constant buffer and the value of each member of the device resource object instance, making stepping through DirectX code easy and efficient.

7-debugging

But that is not all what the Visual Studio debugger can do. For example, the Edit and Continue capability allows you to edit your C++ code during a debugging session and see the impact right away without having to rebuild the application, saving a huge amount of development time.

You can find more details in this blog post C++ Debugging and Diagnostics.

Visual Studio Graphics Diagnostics

Debugging rendering issues

Rendering problems can be very tricky to troubleshoot. Whether it’s a position offset, color incorrectness, or a flickering problem, Visual Studio Graphics Diagnostics, a.k.a. the Visual Studio graphics debugger, provides an easy way to capture and analyze frames from your DirectX 10, 11, or 12 games locally or remotely. You can inspect each DirectX event, graphics object, pixel history, and the graphics pipeline to understand exactly what occurred during the frame. This tool also captures call stacks for each graphics event, making it easy to navigate back to your C++ code in Visual Studio. Learn more about Visual Studio Graphics Diagnostics.

8-graphics-debugging

Analyze frame performance

If you are looking for ways to increase the frame rate for your DirectX games, Visual Studio Frame Analysis can be very helpful. It analyzes captured frames to look for expensive draw calls and performs experiments on them to explore performance optimization opportunities for you. The results are presented in a useful report, which you can save and inspect later or share with your team members. For more information on how to use this tool, see blog post Visual Studio Graphics Frame Analysis in action!.

9-frame-analysis

Analyze GPU Usage

While the Frame Analysis tool can help pinpoint the expensive draw calls, understanding how your game performs on the CPU and the GPU in real-time is essential as well. The Visual Studio GPU Usage tool collects CPU and GPU performance data in real-time, and it complements Frame Analysis that is performed on captured frames in an offline fashion to provide you a complete view of your game performance. By reading the GPU usage detailed report, you can easily identify where the performance bottleneck is, whether it’s on the CPU or the GPU, and help you locate the potential problematic code in the app. This GPU Usage tool in Visual Studio blog post includes a more detailed introduction to the tool.

10-gpu-usage

Unit testing

Shipping high-quality games requires good testing. Visual Studio ships with a native C++ unit test framework that you can use to write your unit tests. Add a new unit test project to your solution by clicking on menu New->Project and selecting the Native Unit Test Project template. This automatically adds a test project to your solution. In the created unittest1.cpp file in the unit test project, find TEST_METHOD(TestMethod1) to start adding your test logic code. You can then open the Test Explorer window by clicking on menu Test->Window->Test Explorer to run your tests. Also, take advantage of the built-in code coverage tool (menu Test->Analyze Code Coverage) to understand how much of your code has been covered by your unit tests. This gives you confidence in shipping high-quality games.

11-unit-testing

Collaborate with your team members

Building a great game usually involves more than one developer. When it comes to source code storing and sharing and cloud build, Visual Studio Team Services has you covered.

Simply sign up for a free Visual Studio Team Services accountthen you can check in the source code of your DirectX game into Visual Studio Team Services. With your code successfully synced, everyone on your team can now check out, edit, and check back in the source code, making collaborating with other team members super-efficient.

Visual Studio Team Services also simplifies continuous integrations for your games. Create and manage build processes that automatically compile and test your games in the cloud. Wondering if a bug was fixed in this build? By associating work items to code, the work items are listed in the build summary along with code changes and test results.

12-vsts

You can find more details in this blog post Visual Studio for Teams of C++ Developers.

Try out Visual Studio 2017 for C++ game development

Download Visual Studio 2017, try it out and share your feedback. For problems, let us know via the Report a Problem option in the upper right corner of the VISUAL STUDIO title bar. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice.

Bring your existing Qt projects to Visual Studio

$
0
0

Qt framework is an ever growing cross-platform C++ framework, ideal for building desktop, mobile, and even embedded solutions. While you can use CMake to target Qt (if you do, you should read more about the Visual Studio support for CMake), Qt also provides its own Qt-optimized build system called qmake.

If your project is using qmake, this article covers the high-level steps to follow to import your projects into Visual Studio. You can read about other C++ project types in the guide for Bringing your C++ code to Visual Studio.

bringcode-qt

Step 1. Install the QT Visual Studio Extension. From the Marketplace, install the Qt Visual Studio Tools extension.

Step 2. Import your .pro projects into Visual Studio. To do that, select the Qt VS Tools > Open Qt Project File (.pro) to let the extension create a VS solution and project from your existing Qt .pro file. More information on this is available in the Qt docs covering Qt project management in Visual Studio.

What’s next

If you’re new to Visual Studio, learn more by reading the Getting Started with Visual Studio for C and C++ Developer topic (Coming soon!) and the rest of the posts in this Getting Started series aimed at C++ users that are new to Visual Studio. Download Visual Studio 2017 today, try it out and share your feedback.

Viewing all 1541 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>