Install Visual Studio Code for C/C++ programming on Windows and MacOs
- 24-07-2022
- Toanngo92
- 0 Comments
Visual Studio Code is a free source code editor created by Microsoft that works on Windows, Linux and macOS platforms. Features include debugging support, syntax prompts, automatic intelligent code prompts, command block prompts, command block refactoring, Github integration, you can refer to how to use visual studio code in the article. write Visual Studio Code Tutorials and common programmer problems . For C/C++, this toolkit is the most commonly used toolkit by C/C++ programmers today, used on many real projects.
So why do many people still use Dev C++ when studying, but when working in reality, they use visual studio code? For the following basic reasons:
- VScode to install the running environment takes many stages, much more complicated than Dev C ++, but it can accurately simulate the actual running environment. And when working in practice, we need to understand that a stable running environment is very important
- Because it’s close to the real environment, VScode catches errors more tightly, many source codes that run well on Dev C++ to VSCode fail (due to different compilers or versions – you can imagine the Vietnamese dictionary -> English – English is different from Vietnamese -> English – American for easy visualization)
Mục lục
Instructions for installing Visual Studio Code for C programming on Windows operating system
Step 1: Download Visual Studio
You go to https://code.visualstudio.com/download and download the Visual Studio Code installer from the official site. or search vscode keyword and click on the first result returned from google:
Step 2: Install Visual Studio
Step 3: Download the C/C++ Extension (extension) for Visual Studio Code
Step 4: Download and install MinGW
Download Minimalist GNU for Windows here https://sourceforge.net/projects/mingw/
Proceed to click on the file mingw-get-setup.exe to proceed with the installation
Step 5: Create an environment variable for MinGW
Access the newly installed C:MinGWbin folder and press CTRL+C (Copy) to get the environment variable path
Access the Edit the system environment variables feature of windows by typing system environment in the search bar of windows taskbar
With the next steps, continue to click OK to disable the environment variable editor.
Step 6: check the environment variable is recognized by Windows or not
Access to CMD to interact with the computer with a black screen interface (no graphics)
Type this command to check if G++ is installed and recognized
g++ --version
If you get an error in the last steps, go back to the MinGW installation step to make sure MinGW is fully and properly installed!
Step 7: Initialize File and run the first C program “Hello World” with Visual Studio Code
Step 1: Open Visual Studio Code and create a new file
Step 2: start writing a simple code and save it as the source file helloword.c
#include <stdio.h> #include <stdlib.h> int main(void){ printf("Hello World"); return 0; }
Instructions for installing Visual Studio Code for C programming on MacOS
Similar to windows, in MacOS, we also need a command line environment to be able to start C programming, in MacOS we access the Terminal application:
The Terminal window provides us with a command line interface – you can enter commands at the prompt to perform tasks.
Type the command GCC –version and press Enter, If you already have , you will see a text output showing that GCC is installed in the window. If you don’t have the Command line developer tools installed, you’ll see a dialog asking you to install them. Click install to perform the installation
The name of the C compiler (which was installed with the Command Line Tools) is gcc . To check if this is now successfully installed, keep typing “gcc –version” into the command line window. You should see a few lines of output, displaying version information as shown below:
This step is quite similar to that on windows, you proceed to create a new helloworld.c file with the source code of part 1, use the terminal to create an executable file and run the executable file (the executable file on MacOs operating systems does not have one. .exe extension like on windows):
cd <path_to_helloworld.c_file> gcc -o helloworld helloworld.c ./helloworld
In the following article, I have shown how to install Visual Studio Code and MinGW on Windows, install Command Line Tool on MacOs to initialize the C programming environment with gcc compiler in the most detail, If you have any problems, please comment. below, the team will support and respond to you, wish you success!