vscode uses the CMake Tool plugin to build the first CMake helloworld project

1. Linux environment preparation

The demo environment of this machine is:
the host windows11 + vscode
virtual machine is installed with RHEL7.6 system
. Use vscode remote ssh to connect to the linux virtual machine.

1.1 CMake installation

For the installation tutorial of CMake on linux, you can refer to another blog post of mine:
"Installing CMake on linux"

1.2 gcc/g++ installation

This step is optional.

Linux generally has its own gcc/g++ compiler, but the version may be relatively low. For example, the version of gcc/g++ that comes with my RHEL7.6 is 4.8, which is relatively low and may not support some new features. If you want to use a newer gcc/g++ version, you can refer to another blog post of mine:
"Install Red Hat Developer Toolset on Redhat7 and freely switch gcc and g++ versions"

Two, vscode plug-in installation

2 plugins need to be installed. If you use ssh to connect to the virtual machine, you may be prompted to install it on the remote host, just click Install.

2.1 C++ extensions

cpp-extension

2.2 CMake Tool

Search for CMake in extensions, install the CMake Tools plugin,
20221230004455

3. Use CMake to build the first project

3.1 Create project directory

In the terminal of vscode, enter your working directory, then use mkdir to create a project folder, called helloworld in this example, then cd into the directory, use code . to open a new vscode window

[hubing@192 backup]$ mkdir helloworld
[hubing@192 backup]$ cd helloworld
[hubing@192 helloworld]$ code .

20221230005806

At this time, there is nothing in the helloworld directory.

3.2 Create the first Project using CMake Tool

Press Ctrl+Shift+P to execute

CMake: Quick Start

20221230011357

Then you will be prompted to choose a kit, just choose as needed:

20221230011512

Enter the project name and enter as needed:

20221230011745

Then choose to create an executable program in this example:

20221230011919

At this point, you can see that the CMake Tool plugin has created a simple project for us. In the helloworld directory, there are main.cpp, a CMakeLists.txt file, and a build directory.

20221230012114

3.3 Configure the first project

If you need to switch the compiler, or switch the debug/release mode, etc., you can switch accordingly through the button at the bottom of the vscode interface or ctrl + shift + p

  • switch kit
    20221230012536

  • switch variant
    20221230012630

After switching, press Ctrl+Shift+P to reconfigure the project.

20221230012923

4. Construction project

After everything is configured, you can build. You can enter the CMake: Build command through Ctrl+Shift+P, or you can click the build button at the bottom of the interface.

20221230013424

5. Program Debugging

Breakpoints can be set to debug the program.

20221230013613

6. Implementation procedures

20221230013722

7. CMake project description

For a detailed description of the project created in this example, please refer to my other blog post:
Description of the first hello world project created by CMake Tool

Guess you like

Origin blog.csdn.net/hubing_hust/article/details/128490030