仗剑走天涯

个人站

苟若恒,何必三更起五更眠,最无益,莫过一日暴十日寒


vscode

目录

vscode中调试多个C文件

1.准备3个文件

main.h hello.c hello.h

// main.c
#include "hello.h"
int main(){
    printHello();
    return 0;
}

// hello.c  
#include <stdio.h>
#include "hello.h"
void printHello(){
    printf("memeda...");
}

// hello.h
#ifdef HELLO_H__
#define HELLO_H__

void printHello();
#endif

2.调出 tasks.json launch.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            // "command": "D:\\Javainstall\\mingw64\\bin\\gcc.exe",
            // "args": [
            //     "-g",
            //     "${file}",
            //     "${fileDirname}/hello.c",
            //     "-o",
            //     "${fileDirname}\\${fileBasenameNoExtension}.exe"
            // ],
            "command": "D:\\Javainstall\\mingw64\\bin\\make.exe",
            "args": [
                "-C",
                "${workspaceFolder}",
                "all"
            ],
            "options": {
                "cwd": "D:\\Javainstall\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

3.编写 Makefile 文件

objects = main.o hello.o

all:main

main:$(objects)
	gcc -o main $(objects)

main.o: main.c
	gcc  -c -g main.c

hello.o: hello.c hello.h
	gcc -c -g hello.c

.PHONY:clean
clean:
	-rm -rf $(objects)

4.打断点即可进行多个c文件之间的调试

5.可能出现的bug

# 1.闪退
在main.c中添加这样一句
system("pasue");

6.生成代码片段

"娶个名字": {
		"prefix": "mk",
		"body": [
			"\"command\": \"D:\\\\\\Javainstall\\\\\\mingw64\\\\\\bin\\\\\\make.exe\",",
            
            "\"args\": [",
					"\t\"-C\",",
					"\t\"\\${workspaceFolder}\",",
					"\t\"all\"",
					"],",
		],