CMake tasks.json launch.json

这篇具有很好参考价值的文章主要介绍了CMake tasks.json launch.json。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

CMake tasks.json launch.json,CMake 笔记,json,linux,cmake

heheda@linux:~/Linux/cmake/cmakeClass$ tree
.
├── CMakeLists.txt
├── include
│   ├── Gun.h
│   └── Soldier.h
├── main.cpp
└── src
    ├── Gun.cpp
    └── Soldier.cpp

2 directories, 6 files
heheda@linux:~/Linux/cmake/cmakeClass$ 

CMake tasks.json launch.json,CMake 笔记,json,linux,cmake

  • launch.json(在.vscode文件夹中)
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/app",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
            ],
            "preLaunchTask": "Build",
            // "miDebuggerPath": "/usr/bin/gdb"
        },
    ]
}
  • tasks.json(在.vscode文件夹中)
{
    "version": "2.0.0",
    "options": {
        "cwd": "${workspaceFolder}/build"
    },
    "tasks": [
        {
            "type": "shell",
            "label": "cmake",
            "command": "cmake",
            "args": [
                ".."
            ]
        },
        {
            "label": "make",
            "group": "build",
            "command": "make",
            "args": [],
            "problemMatcher": []
        },
        {
            "label": "Build",
            "dependsOrder": "sequence",
            "dependsOn": [
                "cmake",
                "make"
            ]
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++ 生成活动文件",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/bin/app"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "编译器: /usr/bin/g++"
        }
    ]
}
  • settings.json(在.vscode文件夹中)
{
    "files.associations": {
        "ostream": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "head.h": "c"
    }
}
  • Gun.h 
#pragma once  //防止头文件重复包含
#include<string>
class Gun
{
public:
       //构造函数初始化,构造函数直接在头文件中实现
       Gun(std:: string type){
           this->_bullet_count=0;
           this->_type=type;
       }
       //装填子弹
       void addBullet(int bullet_num); 
       //发射子弹的接口
      bool shoot();
 
private:
        int   _bullet_count;
        std:: string _type;   
};
  • Gun.cpp
//.cpp文件写接口函数的实现
#include "Gun.h"
#include<iostream>
using namespace std; 
void Gun::addBullet(int bullet_num)
{
        this-> _bullet_count+=bullet_num;
 
}
bool  Gun::shoot()
{
        if(_bullet_count<=0)
        {
            cout<<" here is no bullet!"<<endl;
            return  false;  //直接返回,程序结束
        }
        cout<<" fire work"<<endl;
        this->_bullet_count-=1;
 
        return true;
 
 
}
  • Soldier.h
#pragma once
#include <string>
#include "Gun.h"
class Soldier
{
public:
    Soldier(std::string name); //构造函数不在头文件中实现
    //因为定义了指针,故构造析构函数
    ~Soldier();
    //为士兵添加一把枪
    void addGun(Gun* ptr_gun );
    //为枪增加子弹的接口
    void addBulletToGun(int num);
    bool fire();
 
private:
    std::string _name; //头文件中必须写std
    Gun *_ptr_gun;
};
  • Soldier.cpp
#include "Soldier.h"

Soldier::Soldier(std::string name) {
    this->_name = name;
    this->_ptr_gun = nullptr;
}

void Soldier::addGun(Gun* ptr_gun) {
    this->_ptr_gun = ptr_gun;
}

void Soldier::addBulletToGun(int num) {
    this->_ptr_gun->addBullet(num);
} 

bool Soldier::fire() {
    return this->_ptr_gun->shoot();
}

Soldier::~Soldier() {
    if(this->_ptr_gun == nullptr) {
       return; 
    }
    delete this->_ptr_gun;
    this->_ptr_gun = nullptr; // 防止野指针
}
  • CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(SOLDIERFIRE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11) # 设置C++标准为C++11(-std=c++11)
set(CMAKE_BUILD_TYPE "Debug")
include_directories(${CMAKE_SOURCE_DIR}/include)
aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_LIST) # 选择src文件夹下面的所有文件
add_executable(app main.cpp ${SRC_LIST})

# 指定输出的路径
set(HOME ${PROJECT_SOURCE_DIR}) # 定义一个变量用于存储一个绝对路径
set(EXECUTABLE_OUTPUT_PATH ${HOME}/bin) # 将拼接好的路径值设置给 EXECUTABLE_OUTPUT_PATH 变量
  • main.cpp
#include "Gun.h"
#include "Soldier.h"
#include <iostream>
//测试函数, 实现一些测试功能
void test()
{
    Soldier sandu("xusanduo");  //实例化Soldier类
    sandu.addGun(new Gun("AK47")); //要传入一个gun,需要先创建一个出来,也就是new一个
    sandu.addBulletToGun(20);
    sandu.fire( );
}
int main( )
{
    test( );
    auto a = 8;
    std::cout << a + 10 << std::endl;
    return 0;
}

执行结果:

heheda@linux:~/Linux/cmake/cmakeClass$ mkdir build
heheda@linux:~/Linux/cmake/cmakeClass$ cd build/
heheda@linux:~/Linux/cmake/cmakeClass/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/heheda/Linux/cmake/cmakeClass/build
heheda@linux:~/Linux/cmake/cmakeClass/build$ make
Scanning dependencies of target app
[ 25%] Building CXX object CMakeFiles/app.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/app.dir/src/Gun.cpp.o
[ 75%] Building CXX object CMakeFiles/app.dir/src/Soldier.cpp.o
[100%] Linking CXX executable ../bin/app
[100%] Built target app
heheda@linux:~/Linux/cmake/cmakeClass/build$

CMake tasks.json launch.json,CMake 笔记,json,linux,cmake文章来源地址https://www.toymoban.com/news/detail-808661.html

到了这里,关于CMake tasks.json launch.json的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vscode编译多文件复杂项目时tasks.json launch.json 的配置

    本文介绍了利用vscode编译复杂工程的方法,包括gcc和cmke编译时 tasks.json launch.json c_cpp_properties.json 的具体配置。 使用例子 c/c++在windows下编译:使用MinGW gcc从零编译项目 编译程序所需要的指令 上述tasks.json相当于在脚本中执行以下几条命令 每一条命令都要在tasks.json中的tasks中

    2024年02月05日
    浏览(34)
  • vscode生成tasks.json、launch.json、c_cpp_properties.json文件

    在你准备放cpp文件的文件夹中打开vscode,然后ctrl+shift+p搜索命令C/C++:Edit Configurations,如下图所示: 进入配置后,修改编译器路径,我这里是下载mingw的是g++编译器,所以填入的是g++.exe的路径,然后在这一栏里继续修改IntelliSense模式,如果用的是g++的话就修改成gcc -x64即可,如

    2024年02月03日
    浏览(38)
  • ubuntu + VScode + C++ + openCV 运行调试launch.json和task.json编写

    近期在学习opencv的使用,在进行多文件编写时遇到了诸多问题,在查阅众多博客之后,问题一个一个解决了,用这篇文章记录下我的解决方法,希望可以为你提供一定的帮助。(新手拙见,欢迎批评指正)。 创建项目并编写代码。我的项目文件结构如下  在创建项目之后,点

    2024年02月14日
    浏览(23)
  • 调试Dynaslam: Ubuntu系统下使用VS Code进行自动化调试Dynaslam的教程,包括tasks.json和launch.json的配置

    将 SET(CMAKE_BUILD_TYPE Release) 修改为 SET(CMAKE_BUILD_TYPE Debug) 不开启编译优化,在编译选项中包含 -g 参数来启用调试符号,使调试器能够准确地设置断点和跟踪代码。 将 cmake .. -DCMAKE_BUILD_TYPE=Release 替换为 cmake -DCMAKE_BUILD_TYPE=Debug .. 同时,将 DynaSLAM/Thirdparty/DBoW2/CMakeLists.txt 和 DynaSL

    2024年02月05日
    浏览(42)
  • windows .vscode的json文件配置 CMake 构建项目 调试窗口中文设置等

    一、CMake 和 mingw64的安装和环境配置  二、tasks.json和launch.json文件配置 tasks.json launch.json  三、CMakeLists.txt文件 四、头文件和源文件 cat.h cat.cpp main.cpp 五、中文乱码问题解决  CMake C/C++程序输出乱码 Clion CMake C/C++程序输出乱码_cmake message 乱码-CSDN博客https://blog.csdn.net/qq_37274323/

    2024年01月24日
    浏览(40)
  • Vscode使用cmake进行debug的配置教学(教你学会写json配置)

    目前csdn上很多的cmake配置,无论是用插件还是写json,都不太方便,经常配置不成功。 比如想要运行slambook里的一些代码,用传统的配置方案都是建立在工作区就在本文件夹创建。 这样的缺点有: 每次切换工作区都要重新配置,麻烦 每次增加外部连接库都要用pkg去find路径,

    2024年02月06日
    浏览(33)
  • CMake学习笔记-VSCode使用Cmake编译C++工程

    Win + MinGW + CMake + Git 官方教程1: https://cmake.org/cmake/help/latest/guide/tutorial/A%20Basic%20Starting%20Point.html 官方教程2: https://cmake.org/cmake/help/book/mastering-cmake/cmake/Help/guide/tutorial/index.html 官方练习材料1:https://github.com/Kitware/CMake.git 官方练习材料2:https://github.com/Kitware/CMake/blob/master/Help/guide

    2024年02月11日
    浏览(42)
  • CMake 学习笔记

    CMake 已经是 C++ 构建系统的事实标准。 主要是对小彭老师的 C++ 视频课程中 CMake 相关部分的一些笔记和整理,视频链接如下 学 C++ 从 CMake 学起 现代 CMake 高级教程 包含视频中的代码和 PPT 的仓库见以下链接 https://github.com/parallel101/course 本笔记重点关注与 CMake 相关的一些知识点

    2024年02月03日
    浏览(26)
  • Cmake笔记记录

    工作后开发内容都是在Linux系统下完成,cmake使用比较频繁,找到一篇很不错的CMake笔记。 记录下来方便自己查阅。 CMake是一种跨平台的编译配置工具,它可以在不同的平台下基于同样的源代码文件生成对应的工程文件。例如Makefile和VS工程. 使用CMake的流程如下: ①编写 CMakeLis

    2024年02月16日
    浏览(22)
  • Vscode g++ cmake 学习笔记

    1 Linux常用指令   2开发环境搭建    3GCC编译器       4th gdb 调试器 5vscode  6cmake            

    2024年03月16日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包