• VSCode的C/C++开发 ===> Windows


    一、开发环境搭建

    ·安装mingw-w64编译器(GCC for Windows 64 & 32 bits)、Cmake工具(选装)

    ·VSCode插件安装

            ·C/C++

            ·cmake

            ·cmake tools

    二、代码实践演练

    ·基于g++命令

            ·g++编译文件,生成带调试信息的可执行文件、并调试

    g++ -g main.cpp -o my_single_swap

            ·g++编译多文件,生成带调试信息的可执行文件、并调试

    g++ -g main.cpp swap.cpp -o my_multi_swap

    默认的tasks.json是编译单个文件的,不会去自动识别多个文件,我们必须手动去配置launch.json和tasks.json这两个文件。

    ·基于cmake

            ·编写最简单的CMakeLists.txt

    project(MYSWAP)

    add_ executable(my_cmake_swap,main.cpp swap.cpp)

            ·进行多文件编译,并调试

    mkdir build

    cd build

    #如果电脑上已安装了VS,可能会调用微软MSVC编译器,使用(cmake -G "MinGW Makefiles" ..) 代替(cmake ..)即可

    #仅第一次使用cmake时使用(cmake -G "MinGw Makefiles" ..) 后面可使用(cmake ..)

    cmake ..

    mingw32 -make. exe

    ·配置json

            ·launch.json --- for debug

    1. {
    2. "configurations": [
    3. {
    4. "name": "C/C++: g++.exe build and debug active file",
    5. "type": "cppdbg",
    6. "request": "launch",
    7. "program": "${fileDirname}/build/my_cmake_swap.exe",
    8. "args": [],
    9. "stopAtEntry": false,
    10. "cwd": "${fileDirname}",
    11. "environment": [],
    12. "externalConsole": false,
    13. "MIMode": "gdb",
    14. "miDebuggerPath": "E:\\mingw64\\bin\\gdb.exe",
    15. "setupCommands": [
    16. {
    17. "description": "Enable pretty-printing for gdb",
    18. "text": "-enable-pretty-printing",
    19. "ignoreFailures": true
    20. },
    21. {
    22. "description": "Set Disassembly Flavor to Intel",
    23. "text": "-gdb-set disassembly-flavor intel",
    24. "ignoreFailures": true
    25. }
    26. ],
    27. "preLaunchTask": "Build"
    28. }
    29. ],
    30. "version": "2.0.0"
    31. }

            ·tasks.json --- for build before debug

    1. {
    2. "version": "2.0.0",
    3. "options": {
    4. "cwd": "${fileDirname}/build"
    5. },
    6. "tasks": [
    7. {
    8. "type": "shell",
    9. "label": "cmake",
    10. "command": "cmake",
    11. "presentation": {
    12. "panel": "new"
    13. },
    14. "args": [
    15. ".."
    16. ],
    17. },
    18. {
    19. "label": "make",
    20. "group": {
    21. "kind": "build",
    22. "isDefault": true
    23. },
    24. "command": "mingw32-make.exe",
    25. "args": [
    26. ],
    27. },
    28. {
    29. "label": "Build",
    30. "dependsOn":[
    31. "cmake",
    32. "make"
    33. ]
    34. },
    35. ],
    36. }

    如若遇到以下问题:

    在setting.json中加入上述框框中的代码即可。

    1. {
    2. "terminal.integrated.defaultProfile.windows": "Command Prompt",
    3. "files.autoSave": "onFocusChange",
    4. "workbench.iconTheme": "material-icon-theme",
    5. "workbench.colorTheme": "Material Theme Ocean",
    6. "workbench.editorAssociations": {
    7. "*.exe": "default"
    8. },
    9. "cmake.configureOnOpen": true,
    10. "cmake.options.advanced": {
    11. "build": {
    12. "statusBarVisibility": "inherit",
    13. "inheritDefault": "visible"
    14. },
    15. "launch": {
    16. "statusBarVisibility": "inherit",
    17. "inheritDefault": "visible"
    18. },
    19. "debug": {
    20. "statusBarVisibility": "inherit",
    21. "inheritDefault": "visible"
    22. }
    23. },
    24. "cmake.options.statusBarVisibility": "visible",
    25. "cmake.showOptionsMovedNotification": false
    26. }
  • 相关阅读:
    一幅长文细学Vue(七)——路由
    SPI、RS232、485、IIC通信协议详细总结
    了解Redis之命令操作
    三种典型电气减压比例阀线性度和短期重复性的对比考核试验
    基于MATLAB开发AUTOSAR软件应用层模块-part11.AUTOSAR Dictionary-2 mapping
    ImageJ软件
    借秋说愁卖产品
    python-爬虫-三字代码网站爬取
    【数据集NO.4】遥感图像数据集汇总
    想学python找不到合适的书籍?它来了!入门python只需要这一本书就够了!
  • 原文地址:https://blog.csdn.net/zhhdbehx/article/details/137755146