I'm mostly using VSCode. I have two questions:
In the case of having a compiler error, VSCode warns you while you are writing the code (before you compile/run your program.) How I can do this?
How I can have the environment so that when I click on run button it compiles, runs and shows me the output in the terminal section?
Maybe this extension could be of help: C/C++ Advanced Lint
Install Microsoft's C/C++ extension and have a look at the documentation. Especially the topic "Create a build task" should be of interest for you (after you've done all the prerequisites steps.
Related
I can't compile any c++ code in VS Code. Whenever I try, it throws me to the settings.json file, where I see this:
{
"python.defaultInterpreterPath": "C:\\Users\\Pavel Sankin\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe",
"python.pythonPath": "C:\\Users\\Pavel Sankin\\Anaconda3"
}
and nothing else. I did install the standard C/C++ extension and tried checking out the official website for help, but there seem to be other things there. VS Code doesn't throw any errors, it just opens this file whenever I try to compile any piece of C++ code.
Any help will be much appreciated.
Have you had this problems before?
Have you install the microsoft C++ compiler toolset? (other compiler works fine too; check VS docs)
Did you open VSCode using the Developer Command Prompt?
Also check this and follow the guide.
I am using VS Code with the CMake Tools extension, and I would like to run a simple MPI program. Everything compiles just fine, and I can run my code in the terminal using
mpiexec -n 6 "path-to-my-workspace\build\my-executable.exe"
However, I would like to set things up so that this gets executed automatically when I press Control + Shift + P > "CMake: Run Without Debugging" (or Shift F5).
I read in the CMake Tools documentation that I could create new launch targets in a launch.json file. However, the VS Code documentation states that
The launch.json file is used to configure the debugger in Visual Studio Code.
I want this for debug, but also for release. Should I still use a launch.json file? I had the same problem in the past when I needed to pass arguments to my main function. What is the right way to do that in VS Code with CMake Tools?
This sounds like two cases of terminology-related confusion.
In VS Code, there are actions to "Run Code" and "Run Without Debugging". You can find more about the distinction between the two in this question. In a nutshell, "Run Code" runs the program inside a debugger program (like gdb), and and "Run Without Debugging" also runs the program, but doesn' run it inside a debugger program.
The two most common build modes are "debug" and "release", where debug includes debugging symbols that enable running in a debugger, and release does not and instead is built with more optimizations. VS Code can run both types of builds without debugging, and can run debug builds in a debugger. For release builds, it can only run outside a debugger.
You specify that you only care to run outside a debugger.
To answer your question "Should I still use a launch.json file?", yes, you can still use a launch.json file.
Also, note:
Tip: The Run action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' will be the same as 'Debug'.
Another note: If the program you wanted to run wasn't a build output of your project, then you would instead probably want to be using tasks.json.
I am programming in C in Visual Studio Code, but I can't compile, as VSC only offers three compilers built in - Node.js, C# Mono, and Extension development. After a little bit of digging I came across the Visual Studio Marketplace. This seemed like the right sort of thing, but only four uncommon languages were there.
I can only assume that C debugging support is built in, I just can't find it or I am going the wrong way about doing it. I attempted to create a new launch.json (the manifest that seems to hold the compiling/debugging settings for each file) and manually entering the GCC binaries that I have, but that didn't end up working. I'm currently stuck manually compiling the C source file I am working on through command prompt.
Would really help if someone could point me in the right direction on what to do.
tl;dr - Help from anyone debugging C in Visual Studio Code
Windows 8, if that matters
Cheers!
Caution
A friendly reminder: The following tutorial is for Linux user instead of Windows
Tutorial
If you want to debug your c++ code with GDB
You can read this ( Debugging your code ) article from Visual Studio Code official website.
Step 1: Compilation
You need to set up task.json for compilation of your cpp file
or simply type in the following command in the command window
g++ -g file.cpp -o file.exe
to generate a debuggable .exe file
Step 2: Set up the launch.json file
To enable debugging, you will need to generate a launch.json file
follow the launch.json example or google others
Step 3: Press (Ctrl+F5) to start compiling
this launch.json file will launch the configuration when you press the shortcut (Ctrl+F5)
Enjoy it!
ps. For those who want to set up tasks.json, you can read this from vscode official (-> TypeScript Hello World)
Press Ctrl + Shift + P to pull up the Command Pallette, and Type ext install cpptools. It will install everything you need to debug C and C++.
Debugging in VS code is very complete, but if you just need to compile and run:
https://code.visualstudio.com/docs/languages/cpp
Look in the debugging section, and it will explain everything.
There is a much easier way to compile and run C code using GCC, no configuration needed:
Install the Code Runner Extension
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:
"code-runner.executorMap": {
"c": "gcc $fullFileName && ./a.out"
}
For Windows:
Install MinGW or Dev C++
Open Environment Variables
In System Variable select Path -> Edit -> New
Copy this C:\Program Files (x86)\Dev-Cpp\MinGW64\bin to the New window.
(If you have MinGW installed copy its /bin path).
To check if you have added it successfully: Open CMD -> Type "gcc" and it should return:
gcc: fatal error: no input files compilation terminated.
Install C/C++ for Visual Studio Code && C/C++ Compile Run || Code Runner
If you installed only C/C++ Compile Run extension you can compile your program using F6/F7
If you installed the second extension you can compile your program using the button in the top bar.
Screenshot: Hello World compiled in VS Code
Just wanted to add that if you want to debug stuff, you should compile with debug information before you debug, otherwise the debugger won't work. So, in g++ you need to do g++ -g source.cpp. The -g flag means that the compiler will insert debugging information into your executable, so that you can run gdb on it.
You need to install C compiler, C/C++ extension, configure launch.json and tasks.json to be able to debug C code.
This article would guide you how to do it: https://medium.com/#jerrygoyal/run-debug-intellisense-c-c-in-vscode-within-5-minutes-3ed956e059d6
EDIT: As of ~March 2016, Microsoft offers a C/C++ extension for Visual Studio Code and therefor the answer I originally gave is no longer valid.
Visual Studio Code doesn't support C/C++ very well. As such it doesn't >naturally support gcc or gdb within the Visual Studio Code application.
The most it will do is syntax highlighting, the advanced features like >intellisense aren't supported with C. You can still compile and debug code >that you wrote in VSC, but you'll need to do that outside the program itself.
I'm trying to start a work in vscode , latest C++ plugin version supports ms debugger, so as I'm mostly working under windows it was a signal to try this.
c++ tools plugin from MS and cmake tools were installed.
my test project was however not built . the problem is clear , but I need an advice from experienced vscode users how to solve this right.
cmake doesn't see vc compiler.
(after using QtCreator) I expected that vscode could detect vc installation... however that's not so. ok, I have a two ways:
fill environment variables INCLUDE/LIB/PATH with a headers, libs and binaries
just run vcvarsall.bat x64
Second way is a simple and reliable. so final question is:
how to run .bat at the begining of vscode start?
(I don't mean write another bat/cmd, prepare the environment and run vscode inside the same script after that)
Although the question is fairly old, I'll try to give a useful answer, in case others stumble across, just like I did.
I believe what you are trying to achieve is not possible. Code inherits the environment it was started with. If you did not launch it from a developer command prompt, you will not be able build and debug. (Building might be possible if every task first starts the vcvarsall.bat, but that slows things down by a lot. Debugging I think will still not work.)
If you are willing to, you can check out vector-of-bools CMake Tools extension which does build automation as well as automatic MSVC detection. It builds using CMake (thus you need to write your build scripts using CMake), but it will take care of building just by pressing F7, like what most VS users are familiar with.
I am using Xamarin Studio as a D environment. I followed all the instructions given here, and the environment works OK. However, whenever I click the 'play' button in the corner, which is meant to build and run my project, regardless of which settings I give it, I can't get it to run. More specifically, the build succeeds, but then I get an error (which I also can't seem to read the entirety of), which starts with
"Cannot execute [name of my project]. The type initializer for 'MonoDevelop.Debugger.Gdb.D.ToStringExaminatio..."
I've tried searching for answers to this, but have found none. Any and all help would be greatly appreciated.
With Xamarin Studio 4.1.7 on OSX, Mono 3.2.0 and Mono-D 0.5.3.7 and debugger adding 0.2.2, I can start the applications using 'Run without debugging' in the 'Run' menu.
I can't succeed in using the debugger, but I think is an OSX problem: should work on linux.