zoukankan      html  css  js  c++  java
  • windows下使用vs code调试简单的C程序

    常使用visual studio code(vs code)打开.c文件,如果让vs code具备调试技能估计会比较有用

    准备工作:

    1. vs code安装插件:cpptools

    2. windows安装MinGW,然后配置MinGW,需要的工具有gcc,g++,gdb,最后将MinGW的路径添加到path系统环境变量

    写个hello world测试一下(首先需要打开文件夹):

    1. 源程序:test.c

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        int a = 1;
        int b;
    
        printf("Hello vs code!
    ");
    
        b = a;
    
        printf("b = %d
    ", b);
        
        system("pause");
    
        return 0;
    }

    2. 配置tasks.json文件

    使用ctrl+shift+p调出命令对话框,输入:task,选择:configure task runner,继续选择:others,即可产生tasks.json文件,改为如下内容:

    1 {
    2     // See https://go.microsoft.com/fwlink/?LinkId=733558
    3     // for the documentation about the tasks.json format
    4     "version": "0.1.0",
    5     "command": "gcc",
    6     "isShellCommand": true,
    7     "args": ["-g", "${file}", "-o", "${file}.exe"],
    8     "showOutput": "always"
    9 }

    第5行:命令为gcc

    第7行:命令gcc的输入参数,-g表示输出调试信息,-o后接输出文件

    这个task即是用gcc编译源程序了:gcc -g test.c -o test.c.exe

    到这里就可以使用ctrl+shift+b来build源程序了,切换到test.c页面下,使用快捷键即可编译出test.c.exe文件

    顺便打开下方的“终端”选项卡,输入“. est.c.exe”来运行

    3. 配置launch.json文件

    切换到test.c页面,按下F5,在“选择环境”对话框中输入GDB,即选择“C++ (GDB/LLDB)”,产生launch.json文件

    将“program”的值改为:

    "program": "${file}.exe",

    顺便在下面加上一行:

    "miDebuggerPath": "C:\MinGW\bin\gdb.exe",

    这里的miDebuggerPath即为gdb的安装路径。

    切换到test.c页面,按F5即可开始调试

    也可使用windows的编译工具,参见MSDN。不过我的output选项卡窗口中文都出现了乱码

  • 相关阅读:
    monitor system
    monitor disk
    manage account
    windows
    backup daily
    shell 脚本编程概述
    OGNL表达式
    Struts2各个功能详解(2)-输入校验和拦截器
    struts2各个功能详解(1)----参数自动封装和类型自动转换
    Struts2源码解析2
  • 原文地址:https://www.cnblogs.com/heyxiaotang/p/6631802.html
Copyright © 2011-2022 走看看