Skip to content

Intelligent-Embedded-Control-Laboratory/C_CPP_Programming_with_VScode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

C++ programming with Visual Studio Code (Using gcc/g++ with MinGW)

To use the GCC (g++) C/C++ compiler and GDB debugger from mingw-w64, this tutorial teach you about how to install the MinGW and C/C++ extension for VS Code.

Prerequisites

Install Visual Studio Code and C/C++ extension for VS Code

  1. Install Visual Studio Code: choose "Windows" to download the installer.

  1. Choose "I accept" and press "Next".

  1. Set your install path and press "Next".

  1. Press "Next".

  1. Tick these two options for "Open with Code" in "Create code file and enjoy it"

  1. Press "Install".

  1. After the installation finish, close the window and open the VScode.

  1. Install the C/C++ extension for VS Code by searching for 'c++' in the Extensions view (Ctrl+Shift+X).

Install MinGW

  1. Install MinGW - Minimalist GNU for Windows. Please change the directory path to which you can find easily.

  1. Open MinGW Installation Manager, and mark "mingw32-base" and "mingw32-gcc-g++" for installation.

  1. Click "Apply Changes" and "Apply".

  1. Click "Apply".

  1. Wait for the installation.

Add the MinGW path to the Windows PATH environment

  1. Open your Windows Settings.

  1. Search "Edit environment variables for your account (編輯您的帳戶的環境變數)".

  1. Choose the "Path" in user variables, and edit it.

  1. Open your MinGW directory path which you select above to the system path, and copy the path of the bin folder.

  1. Select "New" to add the path of your bin folder under the MinGW directory path.

  1. Select "OK" to save the updated path.

Check your MinGW installation

  1. Search "cmd", and open "Command prompt (命令提示字元)".

  1. Type following command:
gcc --version
g++ --version
gdb --version

  1. If you don't see the version information or the command is not recognized, please check your "path" of MinGW folder and make sure your installation process correctly.

Create code file and enjoy it

  1. You can open your folder and right-click to open with code . (Ref: Step.5 in Install Visual Studio Code and C/C++ extension for VS Code)

  1. You can create a .cpp file by click the "New File" , and program your code.

  • For C:
#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Hello\n");
    return 0;
}
  • For C++:
#include <iostream>

using namespace std;

int main() {
    cout << "Hello" << endl;
    return 0;
}
  1. Press Ctrl+Shift+B and select "C/C++: gcc.exe" or "C/C++: g++.exe" to build your code.

  1. You will find the .exe file in the workspace.

  1. Press Ctrl+Shift+` to open terminal, and type .\FileName.exe to run the executable file.

  1. Congratulation! You have completed the basic environment construction. If there is a problem with your compilation step, stay tuned for the next tutorial update. ^_−☆

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors