vscode solves multiple C++ file compilation

1. Brief description of the problem

When writing a C++ course design for others before, the .h and .cpp files need to be written separately, and multiple classes are involved, and vscode cannot be completed directly. The easiest solution is to add the "CMake Tools" plug-in
.

insert image description here
Officially provided by Microsoft.

2. How to use

The usage method can be viewed through the link provided by the plug-in:
insert image description here

2.1 New project

It should be noted that when using cmake, the CMakeLists.txt and build folders can only be created under the first-level directory (folder) of the workspace.

Right-click the workspace to add a folder.
insert image description here

2.2 compile

The files that need to be compiled need to be added to the CMakeLists.txt file. The main modification is the line add_executable

//cmake版本
cmake_minimum_required(VERSION 3.0.0)
//程序版本
project(Account VERSION 0.1.0)

include(CTest)
enable_testing()
//编译出来的可运行文件(Account) 需要编译的文件
add_executable(Account main.cpp Date.cpp Date.h)

set(CPACK_PROJECT_NAME ${
    
    PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${
    
    PROJECT_VERSION})
include(CPack)

You can go to the cmake official website for more information.

2.3 run

The buttons related to cmake are all at the bottom of vscode.
insert image description here
You can select files, generate executable files, and run

3. Reference code

If you can't find the right code all of a sudden, you can go to my git first to have a look, the code is just messy.
github C++ bank account course design

Guess you like

Origin blog.csdn.net/u012949658/article/details/111769646