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
2.2 CMake Tool
Search for CMake in extensions, install the CMake Tools plugin,
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 .
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
Then you will be prompted to choose a kit, just choose as needed:
Enter the project name and enter as needed:
Then choose to create an executable program in this example:
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.
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
-
switch variant
After switching, press Ctrl+Shift+P to reconfigure the project.
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.
5. Program Debugging
Breakpoints can be set to debug the program.
6. Implementation procedures
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