- Visual Studio For Mac Tutorial
- Visual Studio For Mac Can I Program In C++ Tutorial
- C++ Visual Studio For Mac
- Visual Studio For Mac Can I Program In C++ 사용법
- 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?
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 Mortensen12 Answers
There is a much easier way to compile and run C++ code, no configuration needed:
- Install the Code Runner Extension
- Open your C++ code file in Text Editor, then use shortcut
Ctrl+Alt+N
, or pressF1
and then select/typeRun Code
, or right click the Text Editor and then clickRun 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 HanThe 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 File → Preferences → Keyboard 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.
BeeOnRopeA makefile task example for new 2.0.0 tasks.json version.
In the snippet below some comments I hope they will be useful.
attdonaattdonaOut 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...).
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:
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.
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 BezdenVisual Studio For Mac Can I Program In C++ 사용법
Vlad BezdenWith an updated VS Code you can do it in the following manner:
Hit (Ctrl+P) and type:
Open a folder (Ctrl+K & Ctrl+O) and create a new file inside the folder with the extension .cpp (ex: hello.cpp):
Type in your code and hit save.
Hit (Ctrl+Shift+P and type,
Configure task runner
and then selectother
at the bottom of the list.Create a batch file in the same folder with the name build.bat and include the following code to the body of the file:
Edit the task.json file as follows and save it:
Hit (Ctrl+Shift+B to run Build task. This will create the .obj and .exe files for the project.
For debugging the project, Hit F5 and select C++(Windows).
In launch.json file, edit the following line and save the file:
Hit F5.
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.
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 MortensenThe 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:
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.
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).
- 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.
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:
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.
protected by Community♦May 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?