Visual Studio for Mac enables developers to create applications using.NET and C# only. Visual Studio for Mac should also provide support for C++ development, using compilers available on the system (gcc, Clang, etc.).
Saturday, August 6th, 2016
By Michael Suodenjoki, August 2016.
I wanted to play with and test Visual Studio Code's (VSCode) features for doing C++ development on the Mac platform.
At work and in the past 20+ years I've mainly been using Windows, so this is somewhat different and new interesting territory for me. Previously I've used C++ on the Mac at a basic level, but do have *nix experience, e.g. working with GCC compiler, GDB debugger, NetBeans etc.
Nevertheless, this document contain my VSCode experience results, with small how-to guides for getting up and running.
To follow, I do expect that you have a minimal understanding of working with text editors, C++ build/compilation, C++ debugging and terminal shell commands.
Test machine and installed setup:
- Mac OS X Yosemite, version 10.10.5
- XCode 7.2.1, the official development tool for C++ on Mac OS X is assumed installed.
- Xcode Command Line Tools is assumed installed. This will include (Apple's) clang compiler and Standard C/C++ library.
- Visual Studio Code (VSCode) 1.4 is assumed installed.
- VSCode Extension(s):
- Microsoft's C/C++ v0.8.1
- Yasuaki MITANI's C/C++ Clang v0.2.1
- xaver's Clang-Format v0.10.2
Sample C++ code
Let's take a simple Hello World program:
Create project folder structure
VSCode requires (or works best) when a project is residing in its own main folder. This also makes the VSCode EXPLORER pane work appropriately.
- Create a folder e.g.
test(use Finder or Terminal) - Start the VSCode application.
- Create a new file using File, New or Command(⌘)+N.
- Type in the above C++ source code into the new file and save it as a new file, e.g.
test.cppusing File, Save As... or Shift(⇧)+Command(⌘)+S.
To get code completion etc. up and running
To setup include path to point to the Standard C++ headers, I've added a new path /Applications/... to the includePath setting in the c_cpp_properties.json file in the 'Mac' configuration section.
This is also where you would need to add the include path for/if you use a third-party library, e.g. boost.
Formatting your C++ source code with clang-format
To format C++ source code with clang-format, clang-format must be available (installed).
clang-format can most easily be installed by using the Homebrew package manager. See also http://macappstore.org/clang-format/
Activate Terminal with Command(⌘)+Space, type
Terminaland press Enter.Install Homebrew package manager (skip if already installed) by executing shell command:
Install clang-format using Homebrew by executing command:
Verify by running command:
Should output something like, e.g.:
To format your C++ source code file run Shift(⇧)+Alt(⌥)+F. Alternatively start the VSCode's View, Command PaletteShift(⇧)+Command(⌘)+P and search for and run Format Code command.
Tip. You can place your own .clang-format file specifying your own configuration file for the formatting. For options see Clang Format Style Options
Build (compile) your C++ file
As far as I understand there is, as of this writing (August 5, 2016), no such thing as an integrated build command for clang in VSCode. Perhaps it is possible to establish a task runner for it.
I can see several options - at least:
- Compile using clang or g++ on command line, e.g. using bash.
- Example: Stackoverflow: How do I set up VSCode to compile C++ code
- Use CMake or alternative cross-platform build (generator) tools. A great advantage with this is that your project becomes a lot more platform independent.
Both of these options can be used with VSCode's integrated terminal.
Since, I could see that VSCode already have CMake extensions available and know that CMake is quite popular nowadays I though this could be interesting to use.
I'm not at all familiar with CMake, except at the most basic level. I understand what it is. I also know that some people believe it to be difficult to work with. Build tools usually are complex - particular in non-trivial, i.e. real development, environments. So this is not surprising.
Installing CMake

To install CMake:
- Open Terminal, e.g. directly from within VSCode using View, Integrated Terminal to open lower terminal pane in VSCode.
- Run command
brew install cmaketo install CMake via Homebrew. - Run command
cmake --versionto verify version installed. I worked with version 3.6.1. - Also consider to install the VSCode CMake extension, Shift(⇧)+Command(⌘)+X to open the extension view, search for
CMake.
Build with CMake
Create a
CMakeLists.txtfile in the main project folder with the content of:Note: Above does not specify full debug symbols.
Open Terminal and execute:
to create a new
Debugsub-directory. This will eventually also contain a debug version of the executable. SourceExecute command:
This will generate the
Makefilewhich can build debug executable from thetest.cppC++ source file using XCode's C++ compiler (AppleClang).Execute
maketo build the debug executable - named TEST.Output may look something like:
Run the executable with
./TEST. You should see output like:

Debug the program (with LLDB)
You can also debug your executable from within VSCode.
Start VSCode's debug mode using View, Debug or Shift(⇧)+Command(⌘)+D. You'll see that left pane changes to DEBUG and states C++ Launch.
Activate the settings (wheel) icon to open the
launch.jsonfile and ensure that the sections referencing 'program' is specifying the main executable fileTEST.Save the
launch.jsonfile.Select your
test.cppfile and set a breakpoint in a interesting code line, e.g. line 7 wherestd::cout << ...is. You set a breakpoint on a line by either by double-clicking at the beginning of the line (left of line number) or placing the cursor at the line and hit fn 9 (F9). You should notice that the line is added to the lower BREAKPOINTS section in the DEBUG pane, e.g. showing 'test.cpp 7' telling that you've set a breakpoint at line 7 in test.cpp file. There is even a checkbox there where you can disable/enable the breakpoint.Start debugging using fn 5(F5) key. Hopefully you will see that system hits your breakpoint. Also you should see a small panel where you can control how to go along with execution, e.g.:
- Continuefn 5(F5)
- Step Overfn 10(F10)
- Step Intofn 11(F11)
- Step OutShift(⇧)+fn 11(F11)
- RestartShift(⇧)+Command(⌘)+fn 5(F5)
- StopShift(⇧)+fn 5(F5)
If your code contains variables, the current values at the breakpoint is shown in the Local VARIABLES part of the DEBUG pane.
Conclusions
Visual Studio For Mac
What I've got:
- C++ syntax coloring, symbol recognition, intellisense, code completion and code navigation.
- Integrated clang-format code formatting.
- Integrated terminal (command shell).
- CMake integration and build via terminal commands using the generated
Makefile. - Integrated LLDB debugging, with breakpoint, variables, watches fully integrated with source code. However it doesn't show complex structures in a nice way, e.g. the content of a std::string. This is perhaps caused by the debugger rather than vscode itself. See also this github issue.
- Integrated (built-in) markdown and preview support. This text was written in VSCode with Markdown syntax. Info...
How To Use Visual Studio
It do take some time to setup the environment. It is not plug and play. All in all I have a good feeling about VSCode and want to learn more.
How To Use Visual Studio In Mac
Could need (I will add to this list as I found more nice/need-to-have).
Visual Studio Express
- Automatic spell checking (should in my view be an OS feature, so that you get everywhere). See also User Voice topic on the matter.