1.代码编写

首先展示整个工程,如图1

图1

A.c、A.h和test.c如Code1~Code3所示

#include <stdio.h>

void printtt(int x)
{
    int i=0;
    for(i=0; i<x; i++)
    {
        printf("helloworld\n");
    }
}

Code1

#ifndef A_H__
#define A_H__

void printtt(int x);

#endif

Code2

#include <A.h>

int main(void)
{
    printtt(3);
    return 0;
}

Code3

2.添加头文件路径:c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win64",
            "includePath": [
                "${workspaceFolder}/**",

                // 添加头文件路径,可以相对路径,也可以绝对路径
                "Cpriaccc"
            ],
            "defines": [],
            "compilerPath": "C:\\Users\\17820\\Downloads\\ProgramDownLoad\\mingw64\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

3.添加头文件路径,选择需要编译的文件:tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            "command": "C:\\Users\\17820\\Downloads\\ProgramDownLoad\\mingw64\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",

                // 添加需要编译的文件,可以一个一个地添加,可以*.c添加。
                "Cpriaccc\\A.c",
                
                // 添加头文件路径
                "-I",
                "Cpriaccc",

                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐