Compiler C Visual Studio Code

0 views
Skip to first unread message

Kerby Kolpack

unread,
Aug 4, 2024, 5:27:12 PM8/4/24
to luopotmonyl
Cis a compiled language meaning your program's source code must be translated (compiled) before it can be run on your computer. The C/C++ extension doesn't include a C++ compiler or debugger, since VS Code as an editor relies on command-line tools for the development workflow. You need to install these tools or use the tools already installed on your computer.

The output should show you the compiler version and details. If neither are found, make sure your compiler executable is in your platform path (%PATH on Windows, $PATH on Linux and macOS) so that the C/C++ extension can find it. Otherwise, use the instructions in the section below to install a compiler.


Note: If you would prefer a full Integrated Development Environment (IDE), with built-in compilation, debugging, and project templates (File > New Project), there are many options available, such as the Visual Studio Community edition.


In the wizard, choose your desired Installation Folder. Record this directory for later. In most cases, the recommended directory is acceptable. The same applies when you get to setting the start menu shortcuts step. When complete, ensure the Run MSYS2 now box is checked and select Finish. A MSYS2 terminal window will then automatically open.


You should see output that states which versions of GCC, g++ and GDB you have installed. If this is not the case, make sure your PATH entry matches the Mingw-w64 binary location where the compiler tools are located or reference the troubleshooting section.


The "code ." command opens VS Code in the current working folder, which becomes your "workspace". Accept the Workspace Trust dialog by selecting Yes, I trust the authors since this is a folder you created.


GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.


If you run into any issues or have suggestions for the Microsoft C/C++ extension, please file issues and suggestions on GitHub. If you haven't already provided feedback, you can take this quick survey.


Get the latest version of MinGW-w64 via MSYS2, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries. This will provide you with the necessary tools to compile your code, debug it, and configure it to work with IntelliSense.


In the wizard, choose your desired Installation Folder. Record this directory for later. In most cases, the recommended directory is acceptable. The same applies when you get to setting the start menu shortcuts step. When complete, ensure the Run MSYS2 now box is checked and select Finish. This will open a MSYS2 terminal window for you.


You can also enable Auto Save to automatically save your file changes, by selecting File > Auto Save. You can find out more about the other views in the VS Code User Interface documentation.


To see IntelliSense in action,hover over vector or string to see their type information. If you type msg. in line 10, you can see a completion list of recommended member functions to call, all generated by IntelliSense:


Remember, the C++ extension uses the C++ compiler you have installed on your machine to build your program. Make sure you have completed the "Installing the MinGW-w64 toolchain" step before attempting to run and debug helloworld.cpp in VS Code.


From now on, the play button will read from tasks.json to figure out how to build and run your program. You can define multiple build tasks in tasks.json, and whichever task is marked as the default will be used by the play button. In case you need to change the default compiler, you can run Tasks: Configure Default Build Task in the Command Palette. Alternatively you can modify the tasks.json file and remove the default by replacing this segment:


This will advance program execution to the first line of the for loop, and skip over all the internal function calls within the vector and string classes that are invoked when the msg variable is created and initialized. Notice the change in the Variables window on the left.


In this case, the errors are expected because, although the variable names for the loop are now visible to the debugger, the statement has not executed yet, so there is nothing to read at this point. The contents of msg are visible, however, because that statement has completed.


Press Step over again to advance to the next statement in this program (skipping over all the internal code that is executed to initialize the loop). Now, the Variables window shows information about the loop variables.


If you like, you can keep pressing Step over until all the words in the vector have been printed to the console. But if you are curious, try pressing the Step Into button to step through source code in the C++ standard library!


To return to your own code, one way is to keep pressing Step over. Another way is to set a breakpoint in your code by switching to the helloworld.cpp tab in the code editor, putting the insertion point somewhere on the cout statement inside the loop, and pressing F9. A red dot appears in the gutter on the left to indicate that a breakpoint has been set on this line.


Place the insertion point inside the loop. In the Watch window, select the plus sign and in the text box, type word, which is the name of the loop variable. Now view the Watch window as you step through the loop.


There are cases where you'd want to customize your debug configuration, such as specifying arguments to pass to the program at runtime. You can define custom debug configurations in a launch.json file.


In the JSON above, program specifies the program you want to debug. Here it is set to the active file folder ($fileDirname) and active filename with the .exe extension ($fileBasenameNoExtension.exe), which if helloworld.cpp is the active file will be helloworld.exe. The args property is an array of arguments to pass to the program at runtime.


The extension uses the compilerPath setting to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide features like smart completions and Go to Definition navigation.


By downloading, you agree to the licensing terms for the Visual Studio edition you select below. We also offer the ability to download software with Visual Studio. This software is licensed separately, as set out in the 3rd Party Notices or in its accompanying license. By downloading, you also agree to those licenses.


Open a codebase from any environment and get to work right away. Use MSBuild with the Microsoft Visual C++ compiler or a 3rd party toolset like CMake with Clang or mingw to build and debug your code right in the IDE. Benefit from a first-class CMake experience.


Game DevelopmentJoin the many AAA top game studios already using Visual StudioCreate high-performance games with DirectX to run on Windows devices, or build cross-platform games with a top game engine, such as Unity, Unreal, and Cocos. Join the many wildly-successful game studios that already use Visual Studio to boost your productivity with Visual Studio 2022 and the world-class debugger.


Unparalleled Debugging and Diagnostics Write the best, bug-free code Do all the basics like setting breakpoints and stepping through your code, then get more advanced with variable visualization, performance profiling, debugging any local or remote process, and multi-threaded application debugging. Run to click, edit your live code and continue executing without having to rebuild.


Visualize your code with syntax colorization, guidelines, code tooltips, Class View, or Call Hierarchy. Navigate to any code symbol by reference, definition, declaration, and more. Autocomplete your code as you type, quickly repair problems, and refactor your code to your needs. Analyze your code for common issues. Save time that could be better spent.


C++ is a compiled language meaning your program's source code must be translated (compiled) before it can be run on your computer. VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.


Here is a list of compilers and architectures per platform officially supported by the extension. These are reflected by the available IntelliSense modes from the extension's IntelliSense configuration. Note that support for other compilers may be limited.


Known issues

If someone has already filed an issue that encompasses your feedback, please leave a ? or ? reaction on the issue to upvote or downvote it to help us prioritize the issue.




This extension collects usage data and sends it to Microsoft to help improve our products and services. Collection of telemetry is controlled via the same setting provided by Visual Studio Code: "telemetry.enableTelemetry". Read our privacy statement to learn more.


Hi Franklin. Welcome to the Fortran Discourse. VS Code is ultimately a code editor. It does not come with any compilers. There are extensions like fortls that help with writing code but, you would need to install a compiler in addition to VS Code to build your codes.


I use VS Code to build firmware for my 3D printer, but I don't see that it has any advantages for Intel Fortran over Visual Studio. Visual Studio has remote server connection, git integration and more.

3a8082e126
Reply all
Reply to author
Forward
0 new messages