Visual Studio For Mac Can I Program In C++

Posted on  by 

Active1 month ago
  1. Visual Studio For Mac Tutorial
  2. Visual Studio For Mac Can I Program In C++ Tutorial
  3. C++ Visual Studio For Mac
  4. Visual Studio For Mac Can I Program In C++ 사용법
  5. Visual Studio For Mac Wikipedia

Microsoft's Visual Studio Code editor is quite nice, but it has no default support for building C++ projects.

How do I configure it to do this?

Visual Studio For Mac Can I Program In C++

You can buy either one. Doesn't make a difference but. There is a difference in what program that you use for C++. For Windows I use Dev C++. If I were to use a MAC. The latest version of this topic can be found at Visual C++ in Visual Studio. The Visual C++ programming language and development tools help you develop native Universal Windows apps, native desktop and server applications, cross-platform libraries that run on Android and iOS as well as Windows, and managed apps that run on the.NET Framework. C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development using VS Code on Windows, Linux, and macOS. The extension is still in preview and our focus is code editing, navigation, and debugging support for C and C++ code everywhere that VS Code runs.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
user3703887

12 Answers

There is a much easier way to compile and run C++ code, no configuration needed:

  1. Install the Code Runner Extension
  2. Open your C++ code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will be compiled and run, and the output will be shown in the Output Window.

Moreover you could update the config in settings.json using different C++ compilers as you want, the default config for C++ is as below:

Jun HanJun Han
7,0116 gold badges20 silver badges25 bronze badges

The build tasks are project specific. To create a new project, open a directory in Visual Studio Code.

Visual Studio For Mac Tutorial

Following the instructions here, press Ctrl + Shift + P, type Configure Tasks, select it and press Enter.

The tasks.json file will be opened. Paste the following build script into the file, and save it:

Now go to menu FilePreferencesKeyboard Shortcuts, and add the following key binding for the build task:

Now when you press F8 the Makefile will be executed, and errors will be underlined in the editor.

BeeOnRope
29.7k9 gold badges98 silver badges203 bronze badges
user3703887

A makefile task example for new 2.0.0 tasks.json version.

In the snippet below some comments I hope they will be useful.

attdonaattdona
5,3452 gold badges19 silver badges25 bronze badges

Out of frustration at the lack of clear documentation,I've created a Mac project on github that should just work (both building and debugging):

Visual Studio For Mac Can I Program In C++ Tutorial

Note that it requires XCode and the VSCode Microsoft cpptools extension.

C++ Visual Studio For Mac

I plan to do the same for Windows and linux (unless Microsoft write decent documentation first...).

peegee123peegee123

Here is how I configured my VS for C++

Make sure to change appropriete paths to where your MinGW installed

launch.json

tasks.json

c_cpp_properties.json

Reference:

Li KuiLi Kui

If your project has a CMake configuration it's pretty straight forward to setup VSCode, e.g. setup tasks.json like below:

This assumes that there is a folder build in the root of the workspace with a CMake configuration.

There's also a CMake integration extension that adds a 'CMake build' command to VScode.

PS! The problemMatcher is setup for clang-builds. To use GCC I believe you need to change fileLocation to relative, but I haven't tested this.

larsmoalarsmoa
9,4214 gold badges51 silver badges75 bronze badges

Here is how I configured my VS for C++ using g++ compiler and it works great including debugging options:

tasks.json file

launch.json file

I also have 'C/C++ for Visual Studio Code' extension installed in VS Code

Vlad Bezden

Visual Studio For Mac Can I Program In C++ 사용법

Vlad Bezden
36k15 gold badges156 silver badges123 bronze badges

With an updated VS Code you can do it in the following manner:

  1. Hit (Ctrl+P) and type:

  2. Open a folder (Ctrl+K & Ctrl+O) and create a new file inside the folder with the extension .cpp (ex: hello.cpp):

  3. Type in your code and hit save.

  4. Hit (Ctrl+Shift+P and type, Configure task runner and then select other at the bottom of the list.

  5. Create a batch file in the same folder with the name build.bat and include the following code to the body of the file:

  6. Edit the task.json file as follows and save it:

  7. Hit (Ctrl+Shift+B to run Build task. This will create the .obj and .exe files for the project.

  8. For debugging the project, Hit F5 and select C++(Windows).

  9. In launch.json file, edit the following line and save the file:

  10. Hit F5.

mx0
3,5019 gold badges30 silver badges40 bronze badges
PoornamithPoornamith

There's now a C/C++ language extension from Microsoft. You can install it by going to the 'quick open' thing (Ctrl+p) and typing:

You can read about it here:

It's very basic, as of May 2016.

Community
EliotEliot
1,1772 gold badges14 silver badges37 bronze badges

Visual Studio For Mac Wikipedia

You can reference to this latest gist having a version 2.0.0 task for Visual Studio Code, https://gist.github.com/akanshgulati/56b4d469523ec0acd9f6f59918a9e454

You can easily compile and run each file without updating the task. It's generic and also opens the terminal for input entries.

Peter Mortensen
14.4k19 gold badges88 silver badges117 bronze badges
Akansh GulatiAkansh Gulati
6023 gold badges7 silver badges25 bronze badges

The basic problem here is that building and linking a C++ program depends heavily on the build system in use. You will need to support the following distinct tasks, using some combination of plugins and custom code:

  1. General C++ language support for the editor. This is usually done using ms-vscode.cpptools, which most people expect to also handle a lot of other stuff, like build support. Let me save you some time: it doesn't. However, you will probably want it anyway.

  2. Build, clean, and rebuild tasks. This is where your choice of build system becomes a huge deal. You will find plugins for things like CMake and Autoconf (god help you), but if you're using something like Meson and Ninja, you are going to have to write some helper scripts, and configure a custom 'tasks.json' file to handle these. Microsoft has totally changed everything about that file over the last few versions, right down to what it is supposed to be called and the places (yes, placeS) it can go, to say nothing of completely changing the format. Worse, they've SORT OF kept backward compatibility, to be sure to use the 'version' key to specify which variant you want. See details here:

...but note conflicts with:

WARNING: IN ALL OF THE ANSWERS BELOW, ANYTHING THAT BEGINS WITH A 'VERSION' TAG BELOW 2.0.0 IS OBSOLETE.

Here's the closest thing I've got at the moment. Note that I kick most of the heavy lifting off to scripts, this doesn't really give me any menu entries I can live with, and there isn't any good way to select between debug and release without just making another three explicit entries in here. With all that said, here is what I can tolerate as my .vscode/tasks.json file at the moment:

}

Note that, in theory, this file is supposed to work if you put it in the workspace root, so that you aren't stuck checking files in hidden directories (.vscode) into your revision control system. I have yet to see that actually work; test it, but if it fails, put it in .vscode. Either way, the IDE will bitch if it isn't there anyway. (Yes, at the moment, this means I have been forced to check .vscode into subversion, which I'm not happy about.) Note that my build scripts (not shown) simply create (or recreate) a DEBUG directory using, in my case, meson, and build inside it (using, in my case, ninja).

  1. Run, debug, attach, halt. These are another set of tasks, defined in 'launch.json'. Or at least they used to be. Microsoft has made such a hash of the documentation, I'm not even sure anymore.
breakpointbreakpoint

To Build/run C++ projects in VS code , you manually need to configure tasks.json file which is in .vscode folder in workspace folder .To open tasks.json , press ctrl + shift + P , and type Configure tasks , and press enter, it will take you to tasks.json

Here i am providing my tasks.json file with some comments to make the file more understandable , It can be used as a reference for configuring tasks.json , i hope it will be useful

tasks.json

Now , stating directly from the VS code tasks documentation

description of type property :

  • type: The task's type. For a custom task, this can either be shell or process. If shell is specified, the command is interpreted as a shell command (for example: bash, cmd, or PowerShell). If process is specified, the command is interpreted as a process to execute.

The behavior of the terminal can be controlled using thepresentation property in tasks.json . It offers the following properties:

Visual
  • reveal: Controls whether the Integrated Terminal panel is brought to front. Valid values are:

    • always - The panel is always brought to front. This is the default
    • never - The user must explicitly bring the terminal panel to the front using the View > Terminal command (Ctrl+`).
    • silent - The terminal panel is brought to front only if the output is not scanned for errors and warnings.
  • focus: Controls whether the terminal is taking input focus or not. Default is false.

  • echo: Controls whether the executed command is echoed in the terminal. Default is true.
  • showReuseMessage: Controls whether to show the 'Terminal will be reused by tasks, press any key to close it' message.
  • panel: Controls whether the terminal instance is shared between task runs. Possible values are:
    • shared: The terminal is shared and the output of other task runs are added to the same terminal.
    • dedicated: The terminal is dedicated to a specific task. If that task is executed again, the terminal is reused. However, the output of a different task is presented in a different terminal.
    • new: Every execution of that task is using a new clean terminal.
  • clear: Controls whether the terminal is cleared before this task is run. Default is false.
joker007joker007

protected by CommunityMay 22 '16 at 10:53

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Coments are closed