vscode

tasks.json

{
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": []
},
{
"label": "Build",
"dependsOrder": "sequence",
"dependsOn":[
"cmake",
"make"
]
}
],
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
}
}

launch.json

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main_application",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}

main.cpp

#include <iostream>
#include "swap.h"

using namespace std;

int main(){

cout << "hello world" <<endl;
cout << "hello c++ 2020" <<endl;

Swap::run();
Swap::printInfo();

return 0;
}

CMakeLists.txt

# set cmake mini version
cmake_minimum_required(VERSION 3.10)

# set project name
project(HELLOWORLD)

set(CMAKE_BUILD_TYPE Debug)

# include head file
# g++ main.cpp src/swap.cpp -Iinclude -o main
include_directories(include)

# set exec file name
# equal g++ hello.cpp -o main_application
add_executable(main_application hello.cpp src/swap.cpp)

src/swap.cpp

#include "swap.h"
#include <iostream>

void Swap::run()
{
std::cout << "run ..." << std::endl;
}

void Swap::printInfo()
{
std::cout << "printInfo ..." << std::endl;
}

include/swap.h

#ifndef SWAP_H
#define SWAP_H

class Swap
{
public:
static void run();
static void printInfo();
};

#endif

mkdir build
cd build

cmkae …
make
./main