Microsoft's Visual Studio Code editor is quite nice, but it has no default support for building C++ projects.
Active1 month ago
How do I configure it to do this?
Peter Mortensen
The CCS C compiler is a powerful but easy to use C compiler for microcontrollers such as the PICmicro. The C compiler provides lots of libraries for all the peripherals of the microcontrollers (such as Analog-to-digital convert, PWM, timers) as well example programs showing their use. Writing and Running C++ Programs in the Mac OS X 10.4 Environment using xCode JL Popyack. Because Microsoft's Visual Studio only runs in the Windows environment, however, it is impossible to use Visual C++ directly on a Macintosh. The directions below describe how to create, edit, compile, and run a C++ program in the xCode environment. Join Troy Miles for an in-depth discussion in this video, Installing C++ compiler on a Mac, part of C++ IDE Overview. Visual Studio Community 5. Visual Studio Community. Visual Studio for Mac should also provide support for C++ development, using compilers available on the system (gcc, Clang, etc.) 3. Forum: How do I get c++ to work on Read more » Vote Up 0.
14.4k1919 gold badges8888 silver badges117117 bronze badges
user3703887
12 Answers
There is a much easier way to compile and run C++ code, no configuration needed:
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,01166 gold badges2020 silver badges2525 bronze badges
The build tasks are project specific. To create a new project, open a directory in Visual Studio Code.
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.
BeeOnRope
29.7k99 gold badges9898 silver badges203203 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,34522 gold badges1919 silver badges2525 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):
Note that it requires XCode and the VSCode Microsoft cpptools extension.
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 larsmoalarsmoa
problemMatcher is setup for clang -builds. To use GCC I believe you need to change fileLocation to relative , but I haven't tested this.
9,42144 gold badges5151 silver badges7575 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 BezdenVlad Bezden
36k1515 gold badges156156 silver badges123123 bronze badges
With an updated VS Code you can do it in the following manner:
3,50199 gold badges3030 silver badges4040 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,17722 gold badges1414 silver badges3737 bronze badges
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.4k1919 gold badges8888 silver badges117117 bronze badges
Akansh Gulati
Visual C++ Compiler 2010Akansh Gulati
60233 gold badges77 silver badges2525 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:
..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).
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 :
The behavior of the terminal can be controlled using thepresentation property in tasks.json . It offers the following properties:
joker007joker007
protected by Community♦May 22 '16 at 10:53C++ Compiler For Visual Studio Mac Development
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? Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |