美文网首页
VSCode g++编译多个目录中的cpp文件

VSCode g++编译多个目录中的cpp文件

作者: FredricZhu | 来源:发表于2020-11-03 20:03 被阅读0次

tasks.json配置

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build1",
            "command": "D:\\software\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "${workspaceFolder}/rail_class/*",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\software\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

launch.json配置

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\software\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build1"
        }
    ]
}

代码结构


图片.png

代码
main.cpp

#include "rail_class/rail_class.hpp"

int main() {
    int i = 0;
    RAIIClass rail;
    i++; 
    system("pause");
    return 0;
}

rail_class.hpp


#ifndef RAIL_CLASS_HPP
#define RAIL_CLASS_HPP

#include <iostream>
#include <windows.h>
using namespace std;

class RAIIClass {
    public:
        RAIIClass();
        ~RAIIClass();
    private:
        CRITICAL_SECTION mCriticalSection;
};

#endif

rail_class.cpp

#include "rail_class.hpp"


RAIIClass::RAIIClass() {
    InitializeCriticalSection(&this->mCriticalSection);
    EnterCriticalSection(&this->mCriticalSection);
}

RAIIClass::~RAIIClass() {
    LeaveCriticalSection(&this->mCriticalSection);
    DeleteCriticalSection(&this->mCriticalSection); 
    std::cout << "删除 RAIIClass~" << std::endl;
}

相关文章

  • VSCode g++编译多个目录中的cpp文件

    tasks.json配置 launch.json配置 代码结构 代码main.cpp rail_class.hpp...

  • ubuntu下c/c++编译及运行

    编译:g++ lab.cpp运行:g++ -o lab lab.cpp

  • G++/GCC

    gcc和g++的区别主要是在对cpp文件的编译和链接过程中,因为cpp和c文件中库文件的命名方式不同,那为什么g+...

  • C++项目编译

    利用g++命令手动编译 编译单个文件 找到想要编译的文件(这里是main.cpp) 不指定程序名编译 指定一个程序...

  • gcc/g++编译过程

    gcc/g++编译过程阅读笔记 预处理,生成.i的文件g++ -E main.cpp > main.i 预处理后不...

  • 智能指针小例子

    智能指针是放在 memory 头文件中的比如文件名为 test.cpp。则需要 C++11 标准编译g++ -st...

  • 使用cmake构建C/C++项目和动态库

    编译C/C++文件时,很多时候都是直接使用像 gcc main.c 或者 g++ main.cpp 这样的命令编译...

  • 在linux下使用gcc/g++编译多个.h .c 文件

    多个文件编译在linux下编译,下面有三个文件,分别是1.cpp 和 2.cpp 和myhead.h 文件。 1....

  • Cmake 初探

    g++编译 首先我们来看下一个简单的HelloWorld程序怎么编译,编写文件hello.cpp 现在我们使用g+...

  • error: 'cout' was not declared i

    Linux下C++编译出错原因解析 程序: 编译出错:$ g++ s.cpp -o s.outs.cpp: In ...

网友评论

      本文标题:VSCode g++编译多个目录中的cpp文件

      本文链接:https://www.haomeiwen.com/subject/mdpivktx.html